Skip to content

Instantly share code, notes, and snippets.

@IsmailAlamKhan
Created May 1, 2021 09:26
Show Gist options
  • Save IsmailAlamKhan/685cc29d8107c2c1e74a02e86f566edb to your computer and use it in GitHub Desktop.
Save IsmailAlamKhan/685cc29d8107c2c1e74a02e86f566edb to your computer and use it in GitHub Desktop.
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