-
Notifications
You must be signed in to change notification settings - Fork 0
/
cutomChips.dart
192 lines (173 loc) · 4.89 KB
/
cutomChips.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
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:test4/dimensions.dart';
import 'package:test4/widgets/constants.dart';
class CustomChips extends StatefulWidget {
final double width;
final double height;
final Map<String, int> list;
final Function(String) onSelect;
final Color initialColor;
final Color selectedColor;
final Color disabledColor;
final Axis direction;
final EdgeInsetsGeometry padding;
final TextStyle textStyle;
final EdgeInsetsGeometry margin;
final int PersonLimit;
CustomChips({
Key key,
@required this.list,
@required this.onSelect,
@required this.initialColor,
@required this.selectedColor,
@required this.disabledColor,
@required this.direction,
@required this.padding,
@required this.textStyle,
@required this.margin,
@required this.width,
@required this.height,
@required this.PersonLimit
});
@override
_CustomChipsState createState() => _CustomChipsState();
}
class _CustomChipsState extends State<CustomChips> {
String _id;
bool isAbsorbing = true;
List<Map<String, bool>> timeSlots = [
{"9": true},
{"10": true},
{"11": true},
{"12": true},
{"13": true},
{"14": true},
{"15": true},
{"16": true},
{"17": true},
{"18": true},
{"19": true},
{"20": true},
];
getData() {
Map<String, bool> temp = {};
widget.list.forEach((key, value) {
if (value > widget.PersonLimit) { //
temp[key] = false;
}
});
temp.forEach(
(key, value) {
for (int i = 0; i < timeSlots.length; i++) {
if (timeSlots[i].containsKey(key)) {
timeSlots[i] = {key: value};
break;
}
}
},
);
// timeSlots.forEach((element) {
// print(element.toString());
// });
}
Widget falseContainer(String id) => AbsorbPointer(
absorbing: this.isAbsorbing,
child: GestureDetector(
onTap: () => Scaffold.of(context).showSnackBar(SnackBar(
backgroundColor: Color(kdark),
content: Text("Sorry.. the slot is already filled.",style: TextStyle(fontFamily: 'gil',fontSize: Dimensions.boxHeight*2,color: Colors.white),),
)),
child: Container(
width: widget.width,
height: widget.height,
margin: widget.margin,
padding: this.widget.padding,
alignment: Alignment(0, 0),
decoration: BoxDecoration(
color: widget.disabledColor,
borderRadius: BorderRadius.circular(Dimensions.boxHeight),
),
child: Text(
id,
style: widget.textStyle,
),
),
),
);
Widget trueContainer(String id, Color colours,Color textColour) {
return AbsorbPointer(
absorbing: this.isAbsorbing,
child: GestureDetector(
onTap: () {
this._id = id;
setState(() {});
return widget.onSelect(id);
},
child: Container(
width: widget.width,
height: widget.height,
margin: widget.margin,
padding: this.widget.padding,
alignment: Alignment(0, 0),
decoration: BoxDecoration(
color: colours,
borderRadius: BorderRadius.circular(Dimensions.boxHeight),
),
child: Text(
id,
style: widget.textStyle.copyWith(color:textColour),
),
),
),
);
}
List<Widget> generateWidget(String id) {
List<Widget> widgetList = [];
timeSlots.forEach((element) {
if (element.containsValue(false)) {
widgetList.add(falseContainer(element.keys.elementAt(0)));
} else {
if (id == null)
widgetList.add(
trueContainer(element.keys.elementAt(0), widget.initialColor,Colors.black));
else if (id == element.keys.elementAt(0)) {
widgetList.add(
trueContainer(element.keys.elementAt(0), widget.selectedColor,Colors.white));
} else {
widgetList.add(
trueContainer(element.keys.elementAt(0), widget.initialColor,Colors.black));
}
//else if()
}
});
setState(() {});
return widgetList;
}
@override
Widget build(BuildContext context) {
timeSlots = [
{"9": true},
{"10": true},
{"11": true},
{"12": true},
{"13": true},
{"14": true},
{"15": true},
{"16": true},
{"17": true},
{"18": true},
{"19": true},
{"20": true},
];
if (widget.list.isEmpty) {
this.isAbsorbing = true;
} else
this.isAbsorbing = false;
getData();
return Wrap(
direction: widget.direction,
children: generateWidget(this._id),
);
}
}