Created
March 18, 2021 00:35
-
-
Save zohaib304/6cc2e130b02c789eeb88c874a7737d77 to your computer and use it in GitHub Desktop.
Flutter Choice Chips
This file contains 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
class _MyChoiceChipState extends State<MyChoiceChip> { | |
// List<ChoiceChipData> chips = ChoiceChipAll.all; | |
List<String> _options = [ | |
'9th Class', | |
'10th Class', | |
'Fsc Part 1', | |
'Fsc Part 2', | |
'Entry test' | |
]; | |
int _selectedIndex; | |
Widget _buildChips() { | |
List<Widget> chips = []; | |
for (int i = 0; i < _options.length; i++) { | |
ChoiceChip choiceChip = ChoiceChip( | |
selected: _selectedIndex == i, | |
label: Text(_options[i], style: TextStyle(color: Colors.white)), | |
elevation: 3, | |
pressElevation: 5, | |
backgroundColor: Colors.blue, | |
selectedColor: Colors.green, | |
onSelected: (bool selected) { | |
setState(() { | |
if (selected) { | |
_selectedIndex = i; | |
} | |
}); | |
}, | |
); | |
chips.add(choiceChip); | |
} | |
return Wrap( | |
spacing: 15, | |
// mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: chips, | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
children: [ | |
_buildChips(), | |
_selectedIndex == null | |
? Container() | |
: ElevatedButton( | |
onPressed: () { | |
Navigator.of(context).push( | |
MaterialPageRoute( | |
builder: (_) => SecondPage( | |
selectedValue: _selectedIndex, | |
), | |
), | |
); | |
}, | |
child: Text('Continue')) | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment