-
Notifications
You must be signed in to change notification settings - Fork 417
Expand file tree
/
Copy pathsort_group.dart
More file actions
74 lines (67 loc) · 2.01 KB
/
sort_group.dart
File metadata and controls
74 lines (67 loc) · 2.01 KB
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
import 'package:flutter/material.dart';
class SortGroup extends StatefulWidget {
final List<String> children;
final Function onChange;
const SortGroup({Key? key, required this.children, required this.onChange})
: super(key: key);
@override
_SortGroupState createState() => _SortGroupState();
}
class _SortGroupState extends State<SortGroup> {
int index = 0;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return SegmentedButton(
style: ButtonStyle(backgroundColor:
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) {
return null;
}
if (states.contains(MaterialState.selected)) {
return Theme.of(context).colorScheme.secondaryContainer;
}
return Theme.of(context).colorScheme.surface;
})),
segments: [
for (int index = 0; index < widget.children.length; index++)
ButtonSegment(value: index, label: Text(widget.children[index])),
],
selected: {index},
onSelectionChanged: (Set<int> p0) {
widget.onChange(p0.first);
if (mounted)
setState(() {
this.index = p0.first;
});
},
);
}
Widget _buildChip(String i, BuildContext context) {
final bgColor = index == widget.children.indexOf(i)
? Colors.white
: Theme.of(context).textTheme.bodyLarge!.color;
return ElevatedButton(
child: Text(
i,
style: TextStyle(color: bgColor),
),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(
index == widget.children.indexOf(i)
? Theme.of(context).colorScheme.primary
: Theme.of(context).cardColor)),
onPressed: () {
int ii = widget.children.indexOf(i);
widget.onChange(ii);
if (mounted)
setState(() {
this.index = ii;
});
},
);
}
}