-
Notifications
You must be signed in to change notification settings - Fork 260
/
Copy pathchoices_grouped.dart
105 lines (101 loc) · 3.53 KB
/
choices_grouped.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
import 'package:flutter/material.dart';
import 'package:smart_select/smart_select.dart';
import 'package:sticky_headers/sticky_headers.dart';
import '../choices.dart' as choices;
class FeaturesChoicesGrouped extends StatefulWidget {
@override
_FeaturesChoicesGroupedState createState() => _FeaturesChoicesGroupedState();
}
class _FeaturesChoicesGroupedState extends State<FeaturesChoicesGrouped> {
String _smartphone = '';
List<String> _car = [];
Color get primaryColor => Theme.of(context).primaryColor;
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
const SizedBox(height: 7),
SmartSelect<String>.single(
title: 'Smartphones',
placeholder: 'Choose one',
selectedValue: _smartphone,
onChange: (selected) {
setState(() => _smartphone = selected.value);
},
choiceItems: S2Choice.listFrom<String, Map>(
source: choices.smartphones,
value: (index, item) => item['id'],
title: (index, item) => item['name'],
group: (index, item) => item['brand'],
),
groupEnabled: true,
groupSortBy: S2GroupSort.byCountInDesc(),
modalType: S2ModalType.bottomSheet,
tileBuilder: (context, state) {
return S2Tile(
title: state.titleWidget,
value: state.selected.toWidget(),
onTap: state.showModal,
isTwoLine: true,
leading: const CircleAvatar(
backgroundImage: NetworkImage(
'https://source.unsplash.com/xsGxhtAsfSA/100x100',
),
),
);
},
),
const Divider(indent: 20),
SmartSelect<String>.multiple(
title: 'Cars',
placeholder: 'Choose one or more',
selectedValue: _car,
onChange: (selected) => setState(() => _car = selected.value),
choiceItems: S2Choice.listFrom<String, Map>(
source: choices.cars,
value: (index, item) => item['value'],
title: (index, item) => item['title'],
group: (index, item) => item['body'],
),
choiceActiveStyle: const S2ChoiceStyle(color: Colors.redAccent),
modalType: S2ModalType.bottomSheet,
modalConfirm: true,
modalFilter: true,
groupEnabled: true,
groupSortBy: S2GroupSort.byNameInAsc(),
groupBuilder: (context, state, group) {
return StickyHeader(
header: state.groupHeader(group),
content: state.groupChoices(group),
);
},
groupHeaderBuilder: (context, state, group) {
return Container(
color: primaryColor,
padding: const EdgeInsets.all(15),
alignment: Alignment.centerLeft,
child: S2Text(
text: group.name,
highlight: state.filter.value,
highlightColor: Colors.teal,
style: const TextStyle(color: Colors.white),
),
);
},
tileBuilder: (context, state) {
return S2Tile.fromState(
state,
isTwoLine: true,
leading: const CircleAvatar(
backgroundImage: NetworkImage(
'https://source.unsplash.com/yeVtxxPxzbw/100x100',
),
),
);
},
),
const SizedBox(height: 7),
],
);
}
}