Last active
September 9, 2019 21:23
-
-
Save VictorUvarov/dd5d4a79ad5ab1370d9e18b9208fca21 to your computer and use it in GitHub Desktop.
a card to group radial buttons and their descriptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| import 'package:grouped_buttons/grouped_buttons.dart'; | |
| class SelectCard extends StatelessWidget { | |
| final FormFieldValidator<String> validator; | |
| final void Function(String) onSelect; | |
| final List<String> options; | |
| final String selected; | |
| const SelectCard({ | |
| Key key, | |
| @required this.options, | |
| @required this.onSelect, | |
| @required this.selected, | |
| this.validator, | |
| }) : assert(options != null), | |
| assert(selected != null), | |
| super(key: key); | |
| @override | |
| Widget build(BuildContext context) { | |
| return Card( | |
| child: FormField( | |
| initialValue: selected, | |
| validator: validator, | |
| builder: (FormFieldState<String> state) => Column( | |
| children: <Widget>[ | |
| RadioButtonGroup( | |
| picked: selected, | |
| labels: options, | |
| onSelected: (String selected) { | |
| onSelect(selected); | |
| state.didChange(selected); | |
| }, | |
| ), | |
| Align( | |
| alignment: Alignment.centerLeft, | |
| child: state.hasError | |
| ? Padding( | |
| padding: const EdgeInsets.symmetric( | |
| vertical: UiSettings.padding, | |
| horizontal: 30, | |
| ), | |
| child: Text( | |
| state.errorText, | |
| style: Theme.of(context).textTheme.body1.copyWith( | |
| color: KColors.error, | |
| fontSize: 12.0, | |
| ), | |
| ), | |
| ) | |
| : Container(), | |
| ) | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment