@@ -8,15 +8,16 @@ class CustomPicker extends CommonPickerModel {
8
8
return '$value ' .padLeft (length, "0" );
9
9
}
10
10
11
- CustomPicker ({DateTime currentTime, LocaleType locale}) : super (locale: locale) {
11
+ CustomPicker ({DateTime ? currentTime, LocaleType ? locale})
12
+ : super (locale: locale) {
12
13
this .currentTime = currentTime ?? DateTime .now ();
13
14
this .setLeftIndex (this .currentTime.hour);
14
15
this .setMiddleIndex (this .currentTime.minute);
15
16
this .setRightIndex (this .currentTime.second);
16
17
}
17
18
18
19
@override
19
- String leftStringAtIndex (int index) {
20
+ String ? leftStringAtIndex (int index) {
20
21
if (index >= 0 && index < 24 ) {
21
22
return this .digits (index, 2 );
22
23
} else {
@@ -25,7 +26,7 @@ class CustomPicker extends CommonPickerModel {
25
26
}
26
27
27
28
@override
28
- String middleStringAtIndex (int index) {
29
+ String ? middleStringAtIndex (int index) {
29
30
if (index >= 0 && index < 60 ) {
30
31
return this .digits (index, 2 );
31
32
} else {
@@ -34,7 +35,7 @@ class CustomPicker extends CommonPickerModel {
34
35
}
35
36
36
37
@override
37
- String rightStringAtIndex (int index) {
38
+ String ? rightStringAtIndex (int index) {
38
39
if (index >= 0 && index < 60 ) {
39
40
return this .digits (index, 2 );
40
41
} else {
@@ -60,10 +61,20 @@ class CustomPicker extends CommonPickerModel {
60
61
@override
61
62
DateTime finalTime () {
62
63
return currentTime.isUtc
63
- ? DateTime .utc (currentTime.year, currentTime.month, currentTime.day,
64
- this .currentLeftIndex (), this .currentMiddleIndex (), this .currentRightIndex ())
65
- : DateTime (currentTime.year, currentTime.month, currentTime.day, this .currentLeftIndex (),
66
- this .currentMiddleIndex (), this .currentRightIndex ());
64
+ ? DateTime .utc (
65
+ currentTime.year,
66
+ currentTime.month,
67
+ currentTime.day,
68
+ this .currentLeftIndex (),
69
+ this .currentMiddleIndex (),
70
+ this .currentRightIndex ())
71
+ : DateTime (
72
+ currentTime.year,
73
+ currentTime.month,
74
+ currentTime.day,
75
+ this .currentLeftIndex (),
76
+ this .currentMiddleIndex (),
77
+ this .currentRightIndex ());
67
78
}
68
79
}
69
80
@@ -91,7 +102,7 @@ class HomePage extends StatelessWidget {
91
102
body: Center (
92
103
child: Column (
93
104
children: < Widget > [
94
- FlatButton (
105
+ TextButton (
95
106
onPressed: () {
96
107
DatePicker .showDatePicker (context,
97
108
showTitleActions: true ,
@@ -101,10 +112,14 @@ class HomePage extends StatelessWidget {
101
112
headerColor: Colors .orange,
102
113
backgroundColor: Colors .blue,
103
114
itemStyle: TextStyle (
104
- color: Colors .white, fontWeight: FontWeight .bold, fontSize: 18 ),
105
- doneStyle: TextStyle (color: Colors .white, fontSize: 16 )),
115
+ color: Colors .white,
116
+ fontWeight: FontWeight .bold,
117
+ fontSize: 18 ),
118
+ doneStyle:
119
+ TextStyle (color: Colors .white, fontSize: 16 )),
106
120
onChanged: (date) {
107
- print ('change $date in time zone ' + date.timeZoneOffset.inHours.toString ());
121
+ print ('change $date in time zone ' +
122
+ date.timeZoneOffset.inHours.toString ());
108
123
}, onConfirm: (date) {
109
124
print ('confirm $date ' );
110
125
}, currentTime: DateTime .now (), locale: LocaleType .en);
@@ -113,10 +128,12 @@ class HomePage extends StatelessWidget {
113
128
'show date picker(custom theme &date time range)' ,
114
129
style: TextStyle (color: Colors .blue),
115
130
)),
116
- FlatButton (
131
+ TextButton (
117
132
onPressed: () {
118
- DatePicker .showTimePicker (context, showTitleActions: true , onChanged: (date) {
119
- print ('change $date in time zone ' + date.timeZoneOffset.inHours.toString ());
133
+ DatePicker .showTimePicker (context, showTitleActions: true ,
134
+ onChanged: (date) {
135
+ print ('change $date in time zone ' +
136
+ date.timeZoneOffset.inHours.toString ());
120
137
}, onConfirm: (date) {
121
138
print ('confirm $date ' );
122
139
}, currentTime: DateTime .now ());
@@ -125,10 +142,12 @@ class HomePage extends StatelessWidget {
125
142
'show time picker' ,
126
143
style: TextStyle (color: Colors .blue),
127
144
)),
128
- FlatButton (
145
+ TextButton (
129
146
onPressed: () {
130
- DatePicker .showTime12hPicker (context, showTitleActions: true , onChanged: (date) {
131
- print ('change $date in time zone ' + date.timeZoneOffset.inHours.toString ());
147
+ DatePicker .showTime12hPicker (context, showTitleActions: true ,
148
+ onChanged: (date) {
149
+ print ('change $date in time zone ' +
150
+ date.timeZoneOffset.inHours.toString ());
132
151
}, onConfirm: (date) {
133
152
print ('confirm $date ' );
134
153
}, currentTime: DateTime .now ());
@@ -137,13 +156,14 @@ class HomePage extends StatelessWidget {
137
156
'show 12H time picker with AM/PM' ,
138
157
style: TextStyle (color: Colors .blue),
139
158
)),
140
- FlatButton (
159
+ TextButton (
141
160
onPressed: () {
142
161
DatePicker .showDateTimePicker (context,
143
162
showTitleActions: true ,
144
163
minTime: DateTime (2020 , 5 , 5 , 20 , 50 ),
145
164
maxTime: DateTime (2020 , 6 , 7 , 05 , 09 ), onChanged: (date) {
146
- print ('change $date in time zone ' + date.timeZoneOffset.inHours.toString ());
165
+ print ('change $date in time zone ' +
166
+ date.timeZoneOffset.inHours.toString ());
147
167
}, onConfirm: (date) {
148
168
print ('confirm $date ' );
149
169
}, locale: LocaleType .zh);
@@ -152,10 +172,12 @@ class HomePage extends StatelessWidget {
152
172
'show date time picker (Chinese)' ,
153
173
style: TextStyle (color: Colors .blue),
154
174
)),
155
- FlatButton (
175
+ TextButton (
156
176
onPressed: () {
157
- DatePicker .showDateTimePicker (context, showTitleActions: true , onChanged: (date) {
158
- print ('change $date in time zone ' + date.timeZoneOffset.inHours.toString ());
177
+ DatePicker .showDateTimePicker (context, showTitleActions: true ,
178
+ onChanged: (date) {
179
+ print ('change $date in time zone ' +
180
+ date.timeZoneOffset.inHours.toString ());
159
181
}, onConfirm: (date) {
160
182
print ('confirm $date ' );
161
183
}, currentTime: DateTime (2008 , 12 , 31 , 23 , 12 , 34 ));
@@ -164,49 +186,65 @@ class HomePage extends StatelessWidget {
164
186
'show date time picker (English-America)' ,
165
187
style: TextStyle (color: Colors .blue),
166
188
)),
167
- FlatButton (
189
+ TextButton (
168
190
onPressed: () {
169
- DatePicker .showDateTimePicker (context, showTitleActions: true , onChanged: (date) {
170
- print ('change $date in time zone ' + date.timeZoneOffset.inHours.toString ());
191
+ DatePicker .showDateTimePicker (context, showTitleActions: true ,
192
+ onChanged: (date) {
193
+ print ('change $date in time zone ' +
194
+ date.timeZoneOffset.inHours.toString ());
171
195
}, onConfirm: (date) {
172
196
print ('confirm $date ' );
173
- }, currentTime: DateTime (2008 , 12 , 31 , 23 , 12 , 34 ), locale: LocaleType .nl);
197
+ },
198
+ currentTime: DateTime (2008 , 12 , 31 , 23 , 12 , 34 ),
199
+ locale: LocaleType .nl);
174
200
},
175
201
child: Text (
176
202
'show date time picker (Dutch)' ,
177
203
style: TextStyle (color: Colors .blue),
178
204
)),
179
- FlatButton (
205
+ TextButton (
180
206
onPressed: () {
181
- DatePicker .showDateTimePicker (context, showTitleActions: true , onChanged: (date) {
182
- print ('change $date in time zone ' + date.timeZoneOffset.inHours.toString ());
207
+ DatePicker .showDateTimePicker (context, showTitleActions: true ,
208
+ onChanged: (date) {
209
+ print ('change $date in time zone ' +
210
+ date.timeZoneOffset.inHours.toString ());
183
211
}, onConfirm: (date) {
184
212
print ('confirm $date ' );
185
- }, currentTime: DateTime (2008 , 12 , 31 , 23 , 12 , 34 ), locale: LocaleType .ru);
213
+ },
214
+ currentTime: DateTime (2008 , 12 , 31 , 23 , 12 , 34 ),
215
+ locale: LocaleType .ru);
186
216
},
187
217
child: Text (
188
218
'show date time picker (Russian)' ,
189
219
style: TextStyle (color: Colors .blue),
190
220
)),
191
- FlatButton (
221
+ TextButton (
192
222
onPressed: () {
193
- DatePicker .showDateTimePicker (context, showTitleActions: true , onChanged: (date) {
194
- print ('change $date in time zone ' + date.timeZoneOffset.inHours.toString ());
223
+ DatePicker .showDateTimePicker (context, showTitleActions: true ,
224
+ onChanged: (date) {
225
+ print ('change $date in time zone ' +
226
+ date.timeZoneOffset.inHours.toString ());
195
227
}, onConfirm: (date) {
196
228
print ('confirm $date ' );
197
- }, currentTime: DateTime .utc (2019 , 12 , 31 , 23 , 12 , 34 ), locale: LocaleType .de);
229
+ },
230
+ currentTime: DateTime .utc (2019 , 12 , 31 , 23 , 12 , 34 ),
231
+ locale: LocaleType .de);
198
232
},
199
233
child: Text (
200
234
'show date time picker in UTC (German)' ,
201
235
style: TextStyle (color: Colors .blue),
202
236
)),
203
- FlatButton (
237
+ TextButton (
204
238
onPressed: () {
205
- DatePicker .showPicker (context, showTitleActions: true , onChanged: (date) {
206
- print ('change $date in time zone ' + date.timeZoneOffset.inHours.toString ());
239
+ DatePicker .showPicker (context, showTitleActions: true ,
240
+ onChanged: (date) {
241
+ print ('change $date in time zone ' +
242
+ date.timeZoneOffset.inHours.toString ());
207
243
}, onConfirm: (date) {
208
244
print ('confirm $date ' );
209
- }, pickerModel: CustomPicker (currentTime: DateTime .now ()), locale: LocaleType .en);
245
+ },
246
+ pickerModel: CustomPicker (currentTime: DateTime .now ()),
247
+ locale: LocaleType .en);
210
248
},
211
249
child: Text (
212
250
'show custom time picker,\n you can custom picker model like this' ,
0 commit comments