set_time_widget.dart
4.81 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
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
215
216
217
218
219
import 'package:flutter/material.dart';
import 'package:one_key/utils/dialog_util.dart';
import 'package:one_key/utils/utils.dart';
typedef SetTimeCallback = void Function(List value);
class SetTimeWidget {
static SetTimeWidget init = SetTimeWidget();
static List dateData = [
{
'深夜00时': [00, 15, 30, 45]
},
{
'深夜01时': [00, 15, 30, 45]
},
{
'深夜02时': [00, 15, 30, 45]
},
{
'深夜03时': [00, 15, 30, 45]
},
{
'深夜04时': [00, 15, 30, 45]
},
{
'深夜05时': [00, 15, 30, 45]
},
{
'早上06时': [00, 15, 30, 45]
},
{
'早上07时': [00, 15, 30, 45]
},
{
'早上08时': [00, 15, 30, 45]
},
{
'早上09时': [00, 15, 30, 45]
},
{
'中午10时': [00, 15, 30, 45]
},
{
'中午11时': [00, 15, 30, 45]
},
{
'中午12时': [00, 15, 30, 45]
},
{
'中午13时': [00, 15, 30, 45]
},
{
'中午14时': [00, 15, 30, 45]
},
{
'下午15时': [00, 15, 30, 45]
},
{
'下午16时': [00, 15, 30, 45]
},
{
'下午17时': [00, 15, 30, 45]
},
{
'下午18时': [00, 15, 30, 45]
},
{
'晚上19时': [00, 15, 30, 45]
},
{
'晚上20时': [00, 15, 30, 45]
},
{
'晚上21时': [00, 15, 30, 45]
},
{
'晚上22时': [00, 15, 30, 45]
},
{
'晚上23时': [00, 15, 30, 45]
}
];
List feastDateData;
List getFeastDateData(String hourAndMinuteStr) {
// '00:00-00:00'
List hm = _getHourAndMinute(hourAndMinuteStr);
List temp = [];
hm.forEach((e) {
Map map = {e: hm};
temp.add(map);
});
feastDateData = temp;
return temp;
}
//根据获取时间 11:00-12:30 获取30分钟间隔组装的数组
_getHourAndMinute(String hourAndMinuteStr) {
List tempDate = hourAndMinuteStr.split("-");
String beginDate = tempDate[0];
String endDate = tempDate[1];
List tempHour = beginDate.split(':');
/*获取开始小时*/
int beginHour = int.parse(tempHour[0]);
/*获取开始分钟*/
int beginMinute = int.parse(tempHour[1]);
List res = [];
bool tempLimit = true;
while (tempLimit) {
String temp = _dealTime(beginHour, beginMinute);
// bool tempSelect = false;
// Map tempMap = {'title': temp, 'select': tempSelect};
res.add(temp);
if (temp == endDate) {
tempLimit = false;
break;
}
if (beginMinute == 30) {
beginHour++;
if (beginHour >= 24) {
beginHour = 0;
}
}
beginMinute = (beginMinute + 30) % 60;
}
return res;
}
/// 根据时间和分钟组装 格式:11:00
_dealTime(int begin, int mm) {
String sb = '';
if (begin < 10) {
sb = '0$begin';
} else {
sb = '$begin';
}
sb = '$sb:';
if (mm < 10) {
sb = '${sb}0${mm}';
} else {
sb = '${sb}${mm}';
}
return sb;
}
showFeastTimeSelector(
context, data, start, end, SetTimeCallback setTimeCallback) {
DialogUtil.showSelectCusmanDialogNeedCustomHeader(context, data, (value) {
setTimeCallback(value);
}, cancelText: '', title: '选择时间', selecteds: [
_getFirSelectedFeast(start, data),
_getFirSelectedFeast(end, data)
]).then((value) {
print(value);
});
}
//宴会 ------ 第一列当前选中第几个
_getFirSelectedFeast(String start, List data) {
for (int i = 0; i < data.length; i++) {
Map map = data[i];
String key = map.keys.first;
if (key.contains(start)) {
return i;
}
}
return 0;
}
String getSelectTitle(int value) {
if (feastDateData.length > 0) {
Map map = feastDateData[0];
List<dynamic> temp = map[map.keys.first];
return temp[value];
}
}
showTimeSelector(
context, data, hourAndMinute, SetTimeCallback setTimeCallback) {
DialogUtil.showSelectCusmanDialog(context, data, (value) {
setTimeCallback(value);
}, selecteds: [
_getFirSelected(hourAndMinute, data),
_getSecSelected(hourAndMinute)
]).then((value) {
print(value);
});
}
// 第一列当前选中第几个
_getFirSelected(String hourAndMinute, List data) {
String hour = Utils.getHourFromhourAndMinute(hourAndMinute);
for (int i = 0; i < data.length; i++) {
Map map = data[i];
String key = map.keys.first;
if (key.contains(hour)) {
return i;
}
}
return 0;
}
// 第二列当前选中第几个
_getSecSelected(String hourAndMinute) {
String minute = Utils.getMinuteFromhourAndMinute(hourAndMinute);
if (minute == '00') {
return 0;
} else if (minute == '15') {
return 1;
} else if (minute == '30') {
return 2;
}
return 3;
}
}