-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.dart
214 lines (200 loc) · 6.68 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// ignore_for_file: prefer_const_literals_to_create_immutables
import 'package:flutter/material.dart';
import 'package:chip_list/chip_list.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Chip List Demo',
theme: ThemeData(primarySwatch: Colors.teal, primaryColor: Colors.teal),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
final List<String> _dogeNames = [
'Beagle',
'Labrador',
'Retriever',
];
int _currentIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Chip List Demo'),
),
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Basic usage
const Text('Basic usage'),
const SizedBox(
height: 10,
),
Center(
child: ChipList(
listOfChipNames: _dogeNames,
activeBgColorList: [Theme.of(context).primaryColor],
inactiveBgColorList: const [Colors.white],
activeTextColorList: const [Colors.white],
inactiveTextColorList: [Theme.of(context).primaryColor],
listOfChipIndicesCurrentlySelected: [],
activeBorderColorList: [Theme.of(context).primaryColor],
inactiveBorderColorList: [Colors.brown, Colors.pink, Colors.teal],
),
),
const SizedBox(
height: 20,
),
const Text('Basic usage - using border colors'),
const SizedBox(
height: 10,
),
// Without a background color, instead leveraging
// the active and inactive border colors
Center(
child: ChipList(
listOfChipNames: _dogeNames,
activeBgColorList: const [Colors.white],
// activeBgColorList: [Theme.of(context).primaryColor],
inactiveBgColorList: const [Colors.white],
activeTextColorList: [Theme.of(context).primaryColor],
inactiveTextColorList: [Theme.of(context).primaryColor],
listOfChipIndicesCurrentlySelected: [0],
activeBorderColorList: [Theme.of(context).primaryColor],
tooltips: ["Colorful","Plump","Energetic"],
),
),
// Using [supportsMultiSelect]
const SizedBox(
height: 20,
),
const Text(
'Using supportsMultiSelect - using border colors and text color',
),
const SizedBox(
height: 10,
),
ChipList(
listOfChipNames: _dogeNames,
supportsMultiSelect: true,
activeBgColorList: const [Colors.white],
inactiveBgColorList: const [Colors.white],
activeTextColorList: const [
Colors.pink,
Colors.yellow,
Colors.green
],
inactiveTextColorList: [Theme.of(context).primaryColor],
listOfChipIndicesCurrentlySelected: [0],
inactiveBorderColorList: const [Colors.white],
activeBorderColorList: const [
Colors.pink,
Colors.yellow,
Colors.green
],
),
// Using [supportsMultiSelect]
const SizedBox(
height: 20,
),
const Text('Using supportsMultiSelect'),
const SizedBox(
height: 10,
),
ChipList(
listOfChipNames: _dogeNames,
supportsMultiSelect: true,
activeBgColorList: const [
Colors.pink,
Colors.yellow,
Colors.green
],
inactiveBgColorList: const [Colors.white],
activeTextColorList: const [Colors.white],
inactiveTextColorList: [Theme.of(context).primaryColor],
listOfChipIndicesCurrentlySelected: [0],
inactiveBorderColorList: const [
Colors.pink,
Colors.yellow,
Colors.green
],
activeBorderColorList: const [
Colors.pink,
Colors.yellow,
Colors.green
],
),
// Using [extraOnToggle]
const SizedBox(
height: 20,
),
Text('Using extraOnToggle: ${_dogeNames[_currentIndex]}'),
const SizedBox(
height: 10,
),
ChipList(
listOfChipNames: _dogeNames,
activeBgColorList: [Theme.of(context).primaryColor],
inactiveBgColorList: const [Colors.white],
activeTextColorList: const [Colors.white],
inactiveTextColorList: [Theme.of(context).primaryColor],
listOfChipIndicesCurrentlySelected: [_currentIndex],
inactiveBorderColorList: const [Colors.teal],
extraOnToggle: (val) {
_currentIndex = val;
setState(() {});
},
),
// Using [shouldWrap]
const SizedBox(
height: 20,
),
const Text('Using shouldWrap'),
const SizedBox(
height: 10,
),
SizedBox(
width: 150,
child: ChipList(
listOfChipNames: const [
'a',
'really',
'long',
'list',
'of',
'chips',
'that',
'can',
'be',
'wrapped',
],
activeBgColorList: [Theme.of(context).primaryColor],
inactiveBgColorList: const [
Colors.white,
],
activeTextColorList: const [Colors.white],
inactiveTextColorList: [Theme.of(context).primaryColor],
listOfChipIndicesCurrentlySelected: [0],
shouldWrap: true,
runSpacing: 10,
spacing: 10,
),
),
],
),
),
);
}
}