Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit df4ed6f

Browse files
authoredApr 7, 2021
Merge pull request #223 from figengungor/null_safety_feature
Fix #222 : Migrate to sound null safety
2 parents 1d52eb8 + 5804034 commit df4ed6f

File tree

13 files changed

+306
-227
lines changed

13 files changed

+306
-227
lines changed
 

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ International:
5757
## Usage
5858

5959
```
60-
FlatButton(
60+
TextButton(
6161
onPressed: () {
6262
DatePicker.showDatePicker(context,
6363
showTitleActions: true,

‎example/android/app/src/main/AndroidManifest.xml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
additional functionality it is fine to subclass or reimplement
1414
FlutterApplication and put your custom class here. -->
1515
<application
16-
android:name="io.flutter.app.FlutterApplication"
1716
android:label="example"
1817
android:icon="@mipmap/ic_launcher">
1918
<activity
@@ -23,17 +22,26 @@
2322
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
2423
android:hardwareAccelerated="true"
2524
android:windowSoftInputMode="adjustResize">
26-
<!-- This keeps the window background of the activity showing
27-
until Flutter renders its first frame. It can be removed if
28-
there is no splash screen (such as the default splash screen
29-
defined in @style/LaunchTheme). -->
25+
<!-- Specify that the launch screen should continue being displayed -->
26+
<!-- until Flutter renders its first frame. -->
3027
<meta-data
31-
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
32-
android:value="true" />
28+
android:name="io.flutter.embedding.android.SplashScreenDrawable"
29+
android:resource="@drawable/launch_background" />
30+
31+
<!-- Theme to apply as soon as Flutter begins rendering frames -->
32+
<meta-data
33+
android:name="io.flutter.embedding.android.NormalTheme"
34+
android:resource="@style/NormalTheme" />
35+
3336
<intent-filter>
3437
<action android:name="android.intent.action.MAIN"/>
3538
<category android:name="android.intent.category.LAUNCHER"/>
3639
</intent-filter>
3740
</activity>
41+
42+
<meta-data
43+
android:name="flutterEmbedding"
44+
android:value="2" />
45+
3846
</application>
3947
</manifest>
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
package com.realank.example;
2+
import io.flutter.embedding.android.FlutterActivity;
23

3-
import android.os.Bundle;
4-
import io.flutter.app.FlutterActivity;
5-
import io.flutter.plugins.GeneratedPluginRegistrant;
6-
7-
public class MainActivity extends FlutterActivity {
8-
@Override
9-
protected void onCreate(Bundle savedInstanceState) {
10-
super.onCreate(savedInstanceState);
11-
GeneratedPluginRegistrant.registerWith(this);
12-
}
13-
}
4+
public class MainActivity extends FlutterActivity {}

‎example/android/app/src/main/res/values/styles.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@
55
Flutter draws its first frame -->
66
<item name="android:windowBackground">@drawable/launch_background</item>
77
</style>
8+
<!-- You can name this style whatever you'd like -->
9+
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
10+
<item name="android:windowBackground">@drawable/launch_background</item>
11+
</style>
812
</resources>

‎example/ios/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Icon?
4040
/Flutter/Flutter.framework
4141
/Flutter/Generated.xcconfig
4242
/ServiceDefinitions.json
43+
/Flutter/flutter_export_environment.sh
4344

4445
Pods/
4546
.symlinks/

‎example/lib/main.dart

Lines changed: 77 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ class CustomPicker extends CommonPickerModel {
88
return '$value'.padLeft(length, "0");
99
}
1010

11-
CustomPicker({DateTime currentTime, LocaleType locale}) : super(locale: locale) {
11+
CustomPicker({DateTime? currentTime, LocaleType? locale})
12+
: super(locale: locale) {
1213
this.currentTime = currentTime ?? DateTime.now();
1314
this.setLeftIndex(this.currentTime.hour);
1415
this.setMiddleIndex(this.currentTime.minute);
1516
this.setRightIndex(this.currentTime.second);
1617
}
1718

1819
@override
19-
String leftStringAtIndex(int index) {
20+
String? leftStringAtIndex(int index) {
2021
if (index >= 0 && index < 24) {
2122
return this.digits(index, 2);
2223
} else {
@@ -25,7 +26,7 @@ class CustomPicker extends CommonPickerModel {
2526
}
2627

2728
@override
28-
String middleStringAtIndex(int index) {
29+
String? middleStringAtIndex(int index) {
2930
if (index >= 0 && index < 60) {
3031
return this.digits(index, 2);
3132
} else {
@@ -34,7 +35,7 @@ class CustomPicker extends CommonPickerModel {
3435
}
3536

3637
@override
37-
String rightStringAtIndex(int index) {
38+
String? rightStringAtIndex(int index) {
3839
if (index >= 0 && index < 60) {
3940
return this.digits(index, 2);
4041
} else {
@@ -60,10 +61,20 @@ class CustomPicker extends CommonPickerModel {
6061
@override
6162
DateTime finalTime() {
6263
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());
6778
}
6879
}
6980

@@ -91,7 +102,7 @@ class HomePage extends StatelessWidget {
91102
body: Center(
92103
child: Column(
93104
children: <Widget>[
94-
FlatButton(
105+
TextButton(
95106
onPressed: () {
96107
DatePicker.showDatePicker(context,
97108
showTitleActions: true,
@@ -101,10 +112,14 @@ class HomePage extends StatelessWidget {
101112
headerColor: Colors.orange,
102113
backgroundColor: Colors.blue,
103114
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)),
106120
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());
108123
}, onConfirm: (date) {
109124
print('confirm $date');
110125
}, currentTime: DateTime.now(), locale: LocaleType.en);
@@ -113,10 +128,12 @@ class HomePage extends StatelessWidget {
113128
'show date picker(custom theme &date time range)',
114129
style: TextStyle(color: Colors.blue),
115130
)),
116-
FlatButton(
131+
TextButton(
117132
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());
120137
}, onConfirm: (date) {
121138
print('confirm $date');
122139
}, currentTime: DateTime.now());
@@ -125,10 +142,12 @@ class HomePage extends StatelessWidget {
125142
'show time picker',
126143
style: TextStyle(color: Colors.blue),
127144
)),
128-
FlatButton(
145+
TextButton(
129146
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());
132151
}, onConfirm: (date) {
133152
print('confirm $date');
134153
}, currentTime: DateTime.now());
@@ -137,13 +156,14 @@ class HomePage extends StatelessWidget {
137156
'show 12H time picker with AM/PM',
138157
style: TextStyle(color: Colors.blue),
139158
)),
140-
FlatButton(
159+
TextButton(
141160
onPressed: () {
142161
DatePicker.showDateTimePicker(context,
143162
showTitleActions: true,
144163
minTime: DateTime(2020, 5, 5, 20, 50),
145164
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());
147167
}, onConfirm: (date) {
148168
print('confirm $date');
149169
}, locale: LocaleType.zh);
@@ -152,10 +172,12 @@ class HomePage extends StatelessWidget {
152172
'show date time picker (Chinese)',
153173
style: TextStyle(color: Colors.blue),
154174
)),
155-
FlatButton(
175+
TextButton(
156176
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());
159181
}, onConfirm: (date) {
160182
print('confirm $date');
161183
}, currentTime: DateTime(2008, 12, 31, 23, 12, 34));
@@ -164,49 +186,65 @@ class HomePage extends StatelessWidget {
164186
'show date time picker (English-America)',
165187
style: TextStyle(color: Colors.blue),
166188
)),
167-
FlatButton(
189+
TextButton(
168190
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());
171195
}, onConfirm: (date) {
172196
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);
174200
},
175201
child: Text(
176202
'show date time picker (Dutch)',
177203
style: TextStyle(color: Colors.blue),
178204
)),
179-
FlatButton(
205+
TextButton(
180206
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());
183211
}, onConfirm: (date) {
184212
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);
186216
},
187217
child: Text(
188218
'show date time picker (Russian)',
189219
style: TextStyle(color: Colors.blue),
190220
)),
191-
FlatButton(
221+
TextButton(
192222
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());
195227
}, onConfirm: (date) {
196228
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);
198232
},
199233
child: Text(
200234
'show date time picker in UTC (German)',
201235
style: TextStyle(color: Colors.blue),
202236
)),
203-
FlatButton(
237+
TextButton(
204238
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());
207243
}, onConfirm: (date) {
208244
print('confirm $date');
209-
}, pickerModel: CustomPicker(currentTime: DateTime.now()), locale: LocaleType.en);
245+
},
246+
pickerModel: CustomPicker(currentTime: DateTime.now()),
247+
locale: LocaleType.en);
210248
},
211249
child: Text(
212250
'show custom time picker,\nyou can custom picker model like this',

‎example/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ description: A new Flutter application.
1010
version: 1.0.0+1
1111

1212
environment:
13-
sdk: ">=2.0.0-dev.68.0 <3.0.0"
13+
sdk: ">=2.12.0 <3.0.0"
1414

1515
dependencies:
1616
flutter:
1717
sdk: flutter
1818

1919
# The following adds the Cupertino Icons font to your application.
2020
# Use with the CupertinoIcons class for iOS style icons.
21-
cupertino_icons: ^0.1.2
21+
cupertino_icons: ^1.0.2
2222
flutter_datetime_picker:
2323
path: ../
2424

‎lib/flutter_datetime_picker.dart

Lines changed: 76 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ export 'package:flutter_datetime_picker/src/i18n_model.dart';
1313

1414
typedef DateChangedCallback(DateTime time);
1515
typedef DateCancelledCallback();
16-
typedef String StringAtIndexCallBack(int index);
16+
typedef String? StringAtIndexCallBack(int index);
1717

1818
class DatePicker {
1919
///
2020
/// Display date picker bottom sheet.
2121
///
22-
static Future<DateTime> showDatePicker(
22+
static Future<DateTime?> showDatePicker(
2323
BuildContext context, {
2424
bool showTitleActions: true,
25-
DateTime minTime,
26-
DateTime maxTime,
27-
DateChangedCallback onChanged,
28-
DateChangedCallback onConfirm,
29-
DateCancelledCallback onCancel,
25+
DateTime? minTime,
26+
DateTime? maxTime,
27+
DateChangedCallback? onChanged,
28+
DateChangedCallback? onConfirm,
29+
DateCancelledCallback? onCancel,
3030
locale: LocaleType.en,
31-
DateTime currentTime,
32-
DatePickerTheme theme,
31+
DateTime? currentTime,
32+
DatePickerTheme? theme,
3333
}) async {
3434
return await Navigator.push(
3535
context,
@@ -55,16 +55,16 @@ class DatePicker {
5555
///
5656
/// Display time picker bottom sheet.
5757
///
58-
static Future<DateTime> showTimePicker(
58+
static Future<DateTime?> showTimePicker(
5959
BuildContext context, {
6060
bool showTitleActions: true,
6161
bool showSecondsColumn: true,
62-
DateChangedCallback onChanged,
63-
DateChangedCallback onConfirm,
64-
DateCancelledCallback onCancel,
62+
DateChangedCallback? onChanged,
63+
DateChangedCallback? onConfirm,
64+
DateCancelledCallback? onCancel,
6565
locale: LocaleType.en,
66-
DateTime currentTime,
67-
DatePickerTheme theme,
66+
DateTime? currentTime,
67+
DatePickerTheme? theme,
6868
}) async {
6969
return await Navigator.push(
7070
context,
@@ -89,15 +89,15 @@ class DatePicker {
8989
///
9090
/// Display time picker bottom sheet with AM/PM.
9191
///
92-
static Future<DateTime> showTime12hPicker(
92+
static Future<DateTime?> showTime12hPicker(
9393
BuildContext context, {
9494
bool showTitleActions: true,
95-
DateChangedCallback onChanged,
96-
DateChangedCallback onConfirm,
97-
DateCancelledCallback onCancel,
95+
DateChangedCallback? onChanged,
96+
DateChangedCallback? onConfirm,
97+
DateCancelledCallback? onCancel,
9898
locale: LocaleType.en,
99-
DateTime currentTime,
100-
DatePickerTheme theme,
99+
DateTime? currentTime,
100+
DatePickerTheme? theme,
101101
}) async {
102102
return await Navigator.push(
103103
context,
@@ -121,17 +121,17 @@ class DatePicker {
121121
///
122122
/// Display date&time picker bottom sheet.
123123
///
124-
static Future<DateTime> showDateTimePicker(
124+
static Future<DateTime?> showDateTimePicker(
125125
BuildContext context, {
126126
bool showTitleActions: true,
127-
DateTime minTime,
128-
DateTime maxTime,
129-
DateChangedCallback onChanged,
130-
DateChangedCallback onConfirm,
131-
DateCancelledCallback onCancel,
127+
DateTime? minTime,
128+
DateTime? maxTime,
129+
DateChangedCallback? onChanged,
130+
DateChangedCallback? onConfirm,
131+
DateCancelledCallback? onCancel,
132132
locale: LocaleType.en,
133-
DateTime currentTime,
134-
DatePickerTheme theme,
133+
DateTime? currentTime,
134+
DatePickerTheme? theme,
135135
}) async {
136136
return await Navigator.push(
137137
context,
@@ -157,15 +157,15 @@ class DatePicker {
157157
///
158158
/// Display date picker bottom sheet witch custom picker model.
159159
///
160-
static Future<DateTime> showPicker(
160+
static Future<DateTime?> showPicker(
161161
BuildContext context, {
162162
bool showTitleActions: true,
163-
DateChangedCallback onChanged,
164-
DateChangedCallback onConfirm,
165-
DateCancelledCallback onCancel,
163+
DateChangedCallback? onChanged,
164+
DateChangedCallback? onConfirm,
165+
DateCancelledCallback? onCancel,
166166
locale: LocaleType.en,
167-
BasePickerModel pickerModel,
168-
DatePickerTheme theme,
167+
BasePickerModel? pickerModel,
168+
DatePickerTheme? theme,
169169
}) async {
170170
return await Navigator.push(
171171
context,
@@ -190,21 +190,21 @@ class _DatePickerRoute<T> extends PopupRoute<T> {
190190
this.onChanged,
191191
this.onConfirm,
192192
this.onCancel,
193-
theme,
193+
DatePickerTheme? theme,
194194
this.barrierLabel,
195195
this.locale,
196-
RouteSettings settings,
197-
pickerModel,
196+
RouteSettings? settings,
197+
BasePickerModel? pickerModel,
198198
}) : this.pickerModel = pickerModel ?? DatePickerModel(),
199199
this.theme = theme ?? DatePickerTheme(),
200200
super(settings: settings);
201201

202-
final bool showTitleActions;
203-
final DateChangedCallback onChanged;
204-
final DateChangedCallback onConfirm;
205-
final DateCancelledCallback onCancel;
202+
final bool? showTitleActions;
203+
final DateChangedCallback? onChanged;
204+
final DateChangedCallback? onConfirm;
205+
final DateCancelledCallback? onCancel;
206+
final LocaleType? locale;
206207
final DatePickerTheme theme;
207-
final LocaleType locale;
208208
final BasePickerModel pickerModel;
209209

210210
@override
@@ -214,19 +214,19 @@ class _DatePickerRoute<T> extends PopupRoute<T> {
214214
bool get barrierDismissible => true;
215215

216216
@override
217-
final String barrierLabel;
217+
final String? barrierLabel;
218218

219219
@override
220220
Color get barrierColor => Colors.black54;
221221

222-
AnimationController _animationController;
222+
AnimationController? _animationController;
223223

224224
@override
225225
AnimationController createAnimationController() {
226226
assert(_animationController == null);
227227
_animationController =
228-
BottomSheet.createAnimationController(navigator.overlay);
229-
return _animationController;
228+
BottomSheet.createAnimationController(navigator!.overlay!);
229+
return _animationController!;
230230
}
231231

232232
@override
@@ -248,18 +248,18 @@ class _DatePickerRoute<T> extends PopupRoute<T> {
248248

249249
class _DatePickerComponent extends StatefulWidget {
250250
_DatePickerComponent({
251-
Key key,
252-
@required this.route,
251+
Key? key,
252+
required this.route,
253+
required this.pickerModel,
253254
this.onChanged,
254255
this.locale,
255-
this.pickerModel,
256256
}) : super(key: key);
257257

258-
final DateChangedCallback onChanged;
258+
final DateChangedCallback? onChanged;
259259

260260
final _DatePickerRoute route;
261261

262-
final LocaleType locale;
262+
final LocaleType? locale;
263263

264264
final BasePickerModel pickerModel;
265265

@@ -270,7 +270,9 @@ class _DatePickerComponent extends StatefulWidget {
270270
}
271271

272272
class _DatePickerState extends State<_DatePickerComponent> {
273-
FixedExtentScrollController leftScrollCtrl, middleScrollCtrl, rightScrollCtrl;
273+
late FixedExtentScrollController leftScrollCtrl,
274+
middleScrollCtrl,
275+
rightScrollCtrl;
274276

275277
@override
276278
void initState() {
@@ -293,20 +295,20 @@ class _DatePickerState extends State<_DatePickerComponent> {
293295
DatePickerTheme theme = widget.route.theme;
294296
return GestureDetector(
295297
child: AnimatedBuilder(
296-
animation: widget.route.animation,
297-
builder: (BuildContext context, Widget child) {
298+
animation: widget.route.animation!,
299+
builder: (BuildContext context, Widget? child) {
298300
final double bottomPadding = MediaQuery.of(context).padding.bottom;
299301
return ClipRect(
300302
child: CustomSingleChildLayout(
301303
delegate: _BottomPickerLayout(
302-
widget.route.animation.value,
304+
widget.route.animation!.value,
303305
theme,
304-
showTitleActions: widget.route.showTitleActions,
306+
showTitleActions: widget.route.showTitleActions!,
305307
bottomPadding: bottomPadding,
306308
),
307309
child: GestureDetector(
308310
child: Material(
309-
color: theme.backgroundColor ?? Colors.white,
311+
color: theme.backgroundColor,
310312
child: _renderPickerView(theme),
311313
),
312314
),
@@ -319,13 +321,13 @@ class _DatePickerState extends State<_DatePickerComponent> {
319321

320322
void _notifyDateChanged() {
321323
if (widget.onChanged != null) {
322-
widget.onChanged(widget.pickerModel.finalTime());
324+
widget.onChanged!(widget.pickerModel.finalTime()!);
323325
}
324326
}
325327

326328
Widget _renderPickerView(DatePickerTheme theme) {
327329
Widget itemView = _renderItemView(theme);
328-
if (widget.route.showTitleActions) {
330+
if (widget.route.showTitleActions == true) {
329331
return Column(
330332
children: <Widget>[
331333
_renderTitleActionsView(theme),
@@ -350,23 +352,23 @@ class _DatePickerState extends State<_DatePickerComponent> {
350352
child: Container(
351353
padding: EdgeInsets.all(8.0),
352354
height: theme.containerHeight,
353-
decoration: BoxDecoration(color: theme.backgroundColor ?? Colors.white),
355+
decoration: BoxDecoration(color: theme.backgroundColor),
354356
child: NotificationListener(
355357
onNotification: (ScrollNotification notification) {
356358
if (notification.depth == 0 &&
357-
selectedChangedWhenScrollEnd != null &&
358359
notification is ScrollEndNotification &&
359360
notification.metrics is FixedExtentMetrics) {
360-
final FixedExtentMetrics metrics = notification.metrics;
361+
final FixedExtentMetrics metrics =
362+
notification.metrics as FixedExtentMetrics;
361363
final int currentItemIndex = metrics.itemIndex;
362364
selectedChangedWhenScrollEnd(currentItemIndex);
363365
}
364366
return false;
365367
},
366368
child: CupertinoPicker.builder(
367369
key: key,
368-
backgroundColor: theme.backgroundColor ?? Colors.white,
369-
scrollController: scrollController,
370+
backgroundColor: theme.backgroundColor,
371+
scrollController: scrollController as FixedExtentScrollController,
370372
itemExtent: theme.itemHeight,
371373
onSelectedItemChanged: (int index) {
372374
selectedChangedWhenScrolling(index);
@@ -395,7 +397,7 @@ class _DatePickerState extends State<_DatePickerComponent> {
395397

396398
Widget _renderItemView(DatePickerTheme theme) {
397399
return Container(
398-
color: theme.backgroundColor ?? Colors.white,
400+
color: theme.backgroundColor,
399401
child: Row(
400402
mainAxisAlignment: MainAxisAlignment.spaceBetween,
401403
children: <Widget>[
@@ -472,7 +474,7 @@ class _DatePickerState extends State<_DatePickerComponent> {
472474
return Container(
473475
height: theme.titleHeight,
474476
decoration: BoxDecoration(
475-
color: theme.headerColor ?? theme.backgroundColor ?? Colors.white,
477+
color: theme.headerColor ?? theme.backgroundColor,
476478
),
477479
child: Row(
478480
mainAxisAlignment: MainAxisAlignment.spaceBetween,
@@ -489,7 +491,7 @@ class _DatePickerState extends State<_DatePickerComponent> {
489491
onPressed: () {
490492
Navigator.pop(context);
491493
if (widget.route.onCancel != null) {
492-
widget.route.onCancel();
494+
widget.route.onCancel!();
493495
}
494496
},
495497
),
@@ -506,7 +508,7 @@ class _DatePickerState extends State<_DatePickerComponent> {
506508
onPressed: () {
507509
Navigator.pop(context, widget.pickerModel.finalTime());
508510
if (widget.route.onConfirm != null) {
509-
widget.route.onConfirm(widget.pickerModel.finalTime());
511+
widget.route.onConfirm!(widget.pickerModel.finalTime()!);
510512
}
511513
},
512514
),
@@ -517,11 +519,11 @@ class _DatePickerState extends State<_DatePickerComponent> {
517519
}
518520

519521
String _localeDone() {
520-
return i18nObjInLocale(widget.locale)['done'];
522+
return i18nObjInLocale(widget.locale)['done'] as String;
521523
}
522524

523525
String _localeCancel() {
524-
return i18nObjInLocale(widget.locale)['cancel'];
526+
return i18nObjInLocale(widget.locale)['cancel'] as String;
525527
}
526528
}
527529

@@ -535,15 +537,15 @@ class _BottomPickerLayout extends SingleChildLayoutDelegate {
535537
});
536538

537539
final double progress;
538-
final int itemCount;
539-
final bool showTitleActions;
540+
final int? itemCount;
541+
final bool? showTitleActions;
540542
final DatePickerTheme theme;
541543
final double bottomPadding;
542544

543545
@override
544546
BoxConstraints getConstraintsForChild(BoxConstraints constraints) {
545547
double maxHeight = theme.containerHeight;
546-
if (showTitleActions) {
548+
if (showTitleActions == true) {
547549
maxHeight += theme.titleHeight;
548550
}
549551

‎lib/src/date_format.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ String formatDate(DateTime date, List<String> formats, LocaleType locale) {
227227
date.month == now.month &&
228228
date.day == now.day) {
229229
//today
230-
return i18nObjInLocale(locale)['today'];
230+
return i18nObjInLocale(locale)['today'] as String;
231231
} else if (date.year == now.year) {
232232
if (locale == LocaleType.zh) {
233233
return formatDate(date, [mm, '月', dd, '日 ', D], locale);

‎lib/src/date_model.dart

Lines changed: 123 additions & 88 deletions
Large diffs are not rendered by default.

‎lib/src/datetime_picker_theme.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class DatePickerTheme with DiagnosticableTreeMixin {
88
final TextStyle doneStyle;
99
final TextStyle itemStyle;
1010
final Color backgroundColor;
11-
final Color headerColor;
11+
final Color? headerColor;
1212

1313
final double containerHeight;
1414
final double titleHeight;

‎lib/src/i18n_model.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,8 +1307,8 @@ final _i18nModel = <LocaleType, Map<String, Object>>{
13071307
};
13081308

13091309
/// Get international object for [localeType]
1310-
Map<String, Object> i18nObjInLocale(LocaleType localeType) =>
1311-
_i18nModel[localeType] ?? _i18nModel[LocaleType.en];
1310+
Map<String, Object> i18nObjInLocale(LocaleType? localeType) =>
1311+
_i18nModel[localeType] ?? _i18nModel[LocaleType.en] as Map<String, Object>;
13121312

13131313
/// Get international lookup for a [localeType], [key] and [index].
13141314
String i18nObjInLocaleLookup(LocaleType localeType, String key, int index) {

‎pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version: 1.4.0
44
homepage: https://github.com/Realank/flutter_datetime_picker
55

66
environment:
7-
sdk: ">=2.0.0 <3.0.0"
7+
sdk: ">=2.12.0 <3.0.0"
88

99
dependencies:
1010
flutter:

0 commit comments

Comments
 (0)
Please sign in to comment.