Created
May 1, 2021 09:26
-
-
Save IsmailAlamKhan/685cc29d8107c2c1e74a02e86f566edb to your computer and use it in GitHub Desktop.
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'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Material App', | |
home: Home(), | |
); | |
} | |
} | |
class Home extends StatefulWidget { | |
Home({Key? key}) : super(key: key); | |
@override | |
_HomeState createState() => _HomeState(); | |
} | |
class _HomeState extends State<Home> { | |
final Map<String, bool> map = { | |
'Funny': false, | |
'Tech': false, | |
'Beauty': false, | |
'Gaming': false, | |
'Health': false, | |
'Music': false, | |
'Cooking': false, | |
}; | |
void onSelected(bool value, String key) { | |
setState(() { | |
map[key] = value; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(), | |
body: Center( | |
child: Wrap( | |
children: map | |
.map( | |
(key, value) => MapEntry( | |
key, | |
ChoiceChip( | |
label: Text(key), | |
selected: value, | |
onSelected: (val) => onSelected(val, key), | |
), | |
), | |
) | |
.values | |
.toList(), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment