Prechádzať zdrojové kódy

Fix #222 : Migrate to sound null safety

figengungor 4 rokov pred
rodič
commit
f4d2bd02f5

+ 68 - 30
example/lib/main.dart

@@ -8,7 +8,8 @@ class CustomPicker extends CommonPickerModel {
     return '$value'.padLeft(length, "0");
   }
 
-  CustomPicker({DateTime currentTime, LocaleType locale}) : super(locale: locale) {
+  CustomPicker({DateTime? currentTime, LocaleType? locale})
+      : super(locale: locale) {
     this.currentTime = currentTime ?? DateTime.now();
     this.setLeftIndex(this.currentTime.hour);
     this.setMiddleIndex(this.currentTime.minute);
@@ -16,7 +17,7 @@ class CustomPicker extends CommonPickerModel {
   }
 
   @override
-  String leftStringAtIndex(int index) {
+  String? leftStringAtIndex(int index) {
     if (index >= 0 && index < 24) {
       return this.digits(index, 2);
     } else {
@@ -25,7 +26,7 @@ class CustomPicker extends CommonPickerModel {
   }
 
   @override
-  String middleStringAtIndex(int index) {
+  String? middleStringAtIndex(int index) {
     if (index >= 0 && index < 60) {
       return this.digits(index, 2);
     } else {
@@ -34,7 +35,7 @@ class CustomPicker extends CommonPickerModel {
   }
 
   @override
-  String rightStringAtIndex(int index) {
+  String? rightStringAtIndex(int index) {
     if (index >= 0 && index < 60) {
       return this.digits(index, 2);
     } else {
@@ -60,10 +61,20 @@ class CustomPicker extends CommonPickerModel {
   @override
   DateTime finalTime() {
     return currentTime.isUtc
-        ? DateTime.utc(currentTime.year, currentTime.month, currentTime.day,
-            this.currentLeftIndex(), this.currentMiddleIndex(), this.currentRightIndex())
-        : DateTime(currentTime.year, currentTime.month, currentTime.day, this.currentLeftIndex(),
-            this.currentMiddleIndex(), this.currentRightIndex());
+        ? DateTime.utc(
+            currentTime.year,
+            currentTime.month,
+            currentTime.day,
+            this.currentLeftIndex(),
+            this.currentMiddleIndex(),
+            this.currentRightIndex())
+        : DateTime(
+            currentTime.year,
+            currentTime.month,
+            currentTime.day,
+            this.currentLeftIndex(),
+            this.currentMiddleIndex(),
+            this.currentRightIndex());
   }
 }
 
@@ -101,10 +112,14 @@ class HomePage extends StatelessWidget {
                           headerColor: Colors.orange,
                           backgroundColor: Colors.blue,
                           itemStyle: TextStyle(
-                              color: Colors.white, fontWeight: FontWeight.bold, fontSize: 18),
-                          doneStyle: TextStyle(color: Colors.white, fontSize: 16)),
+                              color: Colors.white,
+                              fontWeight: FontWeight.bold,
+                              fontSize: 18),
+                          doneStyle:
+                              TextStyle(color: Colors.white, fontSize: 16)),
                       onChanged: (date) {
-                    print('change $date in time zone ' + date.timeZoneOffset.inHours.toString());
+                    print('change $date in time zone ' +
+                        date.timeZoneOffset.inHours.toString());
                   }, onConfirm: (date) {
                     print('confirm $date');
                   }, currentTime: DateTime.now(), locale: LocaleType.en);
@@ -115,8 +130,10 @@ class HomePage extends StatelessWidget {
                 )),
             TextButton(
                 onPressed: () {
-                  DatePicker.showTimePicker(context, showTitleActions: true, onChanged: (date) {
-                    print('change $date in time zone ' + date.timeZoneOffset.inHours.toString());
+                  DatePicker.showTimePicker(context, showTitleActions: true,
+                      onChanged: (date) {
+                    print('change $date in time zone ' +
+                        date.timeZoneOffset.inHours.toString());
                   }, onConfirm: (date) {
                     print('confirm $date');
                   }, currentTime: DateTime.now());
@@ -127,8 +144,10 @@ class HomePage extends StatelessWidget {
                 )),
             TextButton(
                 onPressed: () {
-                  DatePicker.showTime12hPicker(context, showTitleActions: true, onChanged: (date) {
-                    print('change $date in time zone ' + date.timeZoneOffset.inHours.toString());
+                  DatePicker.showTime12hPicker(context, showTitleActions: true,
+                      onChanged: (date) {
+                    print('change $date in time zone ' +
+                        date.timeZoneOffset.inHours.toString());
                   }, onConfirm: (date) {
                     print('confirm $date');
                   }, currentTime: DateTime.now());
@@ -143,7 +162,8 @@ class HomePage extends StatelessWidget {
                       showTitleActions: true,
                       minTime: DateTime(2020, 5, 5, 20, 50),
                       maxTime: DateTime(2020, 6, 7, 05, 09), onChanged: (date) {
-                    print('change $date in time zone ' + date.timeZoneOffset.inHours.toString());
+                    print('change $date in time zone ' +
+                        date.timeZoneOffset.inHours.toString());
                   }, onConfirm: (date) {
                     print('confirm $date');
                   }, locale: LocaleType.zh);
@@ -154,8 +174,10 @@ class HomePage extends StatelessWidget {
                 )),
             TextButton(
                 onPressed: () {
-                  DatePicker.showDateTimePicker(context, showTitleActions: true, onChanged: (date) {
-                    print('change $date in time zone ' + date.timeZoneOffset.inHours.toString());
+                  DatePicker.showDateTimePicker(context, showTitleActions: true,
+                      onChanged: (date) {
+                    print('change $date in time zone ' +
+                        date.timeZoneOffset.inHours.toString());
                   }, onConfirm: (date) {
                     print('confirm $date');
                   }, currentTime: DateTime(2008, 12, 31, 23, 12, 34));
@@ -166,11 +188,15 @@ class HomePage extends StatelessWidget {
                 )),
             TextButton(
                 onPressed: () {
-                  DatePicker.showDateTimePicker(context, showTitleActions: true, onChanged: (date) {
-                    print('change $date in time zone ' + date.timeZoneOffset.inHours.toString());
+                  DatePicker.showDateTimePicker(context, showTitleActions: true,
+                      onChanged: (date) {
+                    print('change $date in time zone ' +
+                        date.timeZoneOffset.inHours.toString());
                   }, onConfirm: (date) {
                     print('confirm $date');
-                  }, currentTime: DateTime(2008, 12, 31, 23, 12, 34), locale: LocaleType.nl);
+                  },
+                      currentTime: DateTime(2008, 12, 31, 23, 12, 34),
+                      locale: LocaleType.nl);
                 },
                 child: Text(
                   'show date time picker (Dutch)',
@@ -178,11 +204,15 @@ class HomePage extends StatelessWidget {
                 )),
             TextButton(
                 onPressed: () {
-                  DatePicker.showDateTimePicker(context, showTitleActions: true, onChanged: (date) {
-                    print('change $date in time zone ' + date.timeZoneOffset.inHours.toString());
+                  DatePicker.showDateTimePicker(context, showTitleActions: true,
+                      onChanged: (date) {
+                    print('change $date in time zone ' +
+                        date.timeZoneOffset.inHours.toString());
                   }, onConfirm: (date) {
                     print('confirm $date');
-                  }, currentTime: DateTime(2008, 12, 31, 23, 12, 34), locale: LocaleType.ru);
+                  },
+                      currentTime: DateTime(2008, 12, 31, 23, 12, 34),
+                      locale: LocaleType.ru);
                 },
                 child: Text(
                   'show date time picker (Russian)',
@@ -190,11 +220,15 @@ class HomePage extends StatelessWidget {
                 )),
             TextButton(
                 onPressed: () {
-                  DatePicker.showDateTimePicker(context, showTitleActions: true, onChanged: (date) {
-                    print('change $date in time zone ' + date.timeZoneOffset.inHours.toString());
+                  DatePicker.showDateTimePicker(context, showTitleActions: true,
+                      onChanged: (date) {
+                    print('change $date in time zone ' +
+                        date.timeZoneOffset.inHours.toString());
                   }, onConfirm: (date) {
                     print('confirm $date');
-                  }, currentTime: DateTime.utc(2019, 12, 31, 23, 12, 34), locale: LocaleType.de);
+                  },
+                      currentTime: DateTime.utc(2019, 12, 31, 23, 12, 34),
+                      locale: LocaleType.de);
                 },
                 child: Text(
                   'show date time picker in UTC (German)',
@@ -202,11 +236,15 @@ class HomePage extends StatelessWidget {
                 )),
             TextButton(
                 onPressed: () {
-                  DatePicker.showPicker(context, showTitleActions: true, onChanged: (date) {
-                    print('change $date in time zone ' + date.timeZoneOffset.inHours.toString());
+                  DatePicker.showPicker(context, showTitleActions: true,
+                      onChanged: (date) {
+                    print('change $date in time zone ' +
+                        date.timeZoneOffset.inHours.toString());
                   }, onConfirm: (date) {
                     print('confirm $date');
-                  }, pickerModel: CustomPicker(currentTime: DateTime.now()), locale: LocaleType.en);
+                  },
+                      pickerModel: CustomPicker(currentTime: DateTime.now()),
+                      locale: LocaleType.en);
                 },
                 child: Text(
                   'show custom time picker,\nyou can custom picker model like this',

+ 2 - 2
example/pubspec.yaml

@@ -10,7 +10,7 @@ description: A new Flutter application.
 version: 1.0.0+1
 
 environment:
-  sdk: ">=2.0.0-dev.68.0 <3.0.0"
+  sdk: ">=2.12.0 <3.0.0"
 
 dependencies:
   flutter:
@@ -18,7 +18,7 @@ dependencies:
 
   # The following adds the Cupertino Icons font to your application.
   # Use with the CupertinoIcons class for iOS style icons.
-  cupertino_icons: ^0.1.2
+  cupertino_icons: ^1.0.2
   flutter_datetime_picker:
     path: ../
 

+ 71 - 69
lib/flutter_datetime_picker.dart

@@ -13,7 +13,7 @@ export 'package:flutter_datetime_picker/src/i18n_model.dart';
 
 typedef DateChangedCallback(DateTime time);
 typedef DateCancelledCallback();
-typedef String StringAtIndexCallBack(int index);
+typedef String? StringAtIndexCallBack(int index);
 
 class DatePicker {
   ///
@@ -22,14 +22,14 @@ class DatePicker {
   static Future<DateTime> showDatePicker(
     BuildContext context, {
     bool showTitleActions: true,
-    DateTime minTime,
-    DateTime maxTime,
-    DateChangedCallback onChanged,
-    DateChangedCallback onConfirm,
-    DateCancelledCallback onCancel,
+    DateTime? minTime,
+    DateTime? maxTime,
+    DateChangedCallback? onChanged,
+    DateChangedCallback? onConfirm,
+    DateCancelledCallback? onCancel,
     locale: LocaleType.en,
-    DateTime currentTime,
-    DatePickerTheme theme,
+    DateTime? currentTime,
+    DatePickerTheme? theme,
   }) async {
     return await Navigator.push(
       context,
@@ -59,12 +59,12 @@ class DatePicker {
     BuildContext context, {
     bool showTitleActions: true,
     bool showSecondsColumn: true,
-    DateChangedCallback onChanged,
-    DateChangedCallback onConfirm,
-    DateCancelledCallback onCancel,
+    DateChangedCallback? onChanged,
+    DateChangedCallback? onConfirm,
+    DateCancelledCallback? onCancel,
     locale: LocaleType.en,
-    DateTime currentTime,
-    DatePickerTheme theme,
+    DateTime? currentTime,
+    DatePickerTheme? theme,
   }) async {
     return await Navigator.push(
       context,
@@ -92,12 +92,12 @@ class DatePicker {
   static Future<DateTime> showTime12hPicker(
     BuildContext context, {
     bool showTitleActions: true,
-    DateChangedCallback onChanged,
-    DateChangedCallback onConfirm,
-    DateCancelledCallback onCancel,
+    DateChangedCallback? onChanged,
+    DateChangedCallback? onConfirm,
+    DateCancelledCallback? onCancel,
     locale: LocaleType.en,
-    DateTime currentTime,
-    DatePickerTheme theme,
+    DateTime? currentTime,
+    DatePickerTheme? theme,
   }) async {
     return await Navigator.push(
       context,
@@ -124,14 +124,14 @@ class DatePicker {
   static Future<DateTime> showDateTimePicker(
     BuildContext context, {
     bool showTitleActions: true,
-    DateTime minTime,
-    DateTime maxTime,
-    DateChangedCallback onChanged,
-    DateChangedCallback onConfirm,
-    DateCancelledCallback onCancel,
+    DateTime? minTime,
+    DateTime? maxTime,
+    DateChangedCallback? onChanged,
+    DateChangedCallback? onConfirm,
+    DateCancelledCallback? onCancel,
     locale: LocaleType.en,
-    DateTime currentTime,
-    DatePickerTheme theme,
+    DateTime? currentTime,
+    DatePickerTheme? theme,
   }) async {
     return await Navigator.push(
       context,
@@ -160,12 +160,12 @@ class DatePicker {
   static Future<DateTime> showPicker(
     BuildContext context, {
     bool showTitleActions: true,
-    DateChangedCallback onChanged,
-    DateChangedCallback onConfirm,
-    DateCancelledCallback onCancel,
+    DateChangedCallback? onChanged,
+    DateChangedCallback? onConfirm,
+    DateCancelledCallback? onCancel,
     locale: LocaleType.en,
-    BasePickerModel pickerModel,
-    DatePickerTheme theme,
+    BasePickerModel? pickerModel,
+    DatePickerTheme? theme,
   }) async {
     return await Navigator.push(
       context,
@@ -190,21 +190,21 @@ class _DatePickerRoute<T> extends PopupRoute<T> {
     this.onChanged,
     this.onConfirm,
     this.onCancel,
-    theme,
+    DatePickerTheme? theme,
     this.barrierLabel,
     this.locale,
-    RouteSettings settings,
-    pickerModel,
+    RouteSettings? settings,
+    BasePickerModel? pickerModel,
   })  : this.pickerModel = pickerModel ?? DatePickerModel(),
         this.theme = theme ?? DatePickerTheme(),
         super(settings: settings);
 
-  final bool showTitleActions;
-  final DateChangedCallback onChanged;
-  final DateChangedCallback onConfirm;
-  final DateCancelledCallback onCancel;
+  final bool? showTitleActions;
+  final DateChangedCallback? onChanged;
+  final DateChangedCallback? onConfirm;
+  final DateCancelledCallback? onCancel;
+  final LocaleType? locale;
   final DatePickerTheme theme;
-  final LocaleType locale;
   final BasePickerModel pickerModel;
 
   @override
@@ -214,19 +214,19 @@ class _DatePickerRoute<T> extends PopupRoute<T> {
   bool get barrierDismissible => true;
 
   @override
-  final String barrierLabel;
+  final String? barrierLabel;
 
   @override
   Color get barrierColor => Colors.black54;
 
-  AnimationController _animationController;
+  AnimationController? _animationController;
 
   @override
   AnimationController createAnimationController() {
     assert(_animationController == null);
     _animationController =
-        BottomSheet.createAnimationController(navigator.overlay);
-    return _animationController;
+        BottomSheet.createAnimationController(navigator!.overlay!);
+    return _animationController!;
   }
 
   @override
@@ -248,18 +248,18 @@ class _DatePickerRoute<T> extends PopupRoute<T> {
 
 class _DatePickerComponent extends StatefulWidget {
   _DatePickerComponent({
-    Key key,
-    @required this.route,
+    Key? key,
+    required this.route,
+    required this.pickerModel,
     this.onChanged,
     this.locale,
-    this.pickerModel,
   }) : super(key: key);
 
-  final DateChangedCallback onChanged;
+  final DateChangedCallback? onChanged;
 
   final _DatePickerRoute route;
 
-  final LocaleType locale;
+  final LocaleType? locale;
 
   final BasePickerModel pickerModel;
 
@@ -270,7 +270,9 @@ class _DatePickerComponent extends StatefulWidget {
 }
 
 class _DatePickerState extends State<_DatePickerComponent> {
-  FixedExtentScrollController leftScrollCtrl, middleScrollCtrl, rightScrollCtrl;
+  late FixedExtentScrollController leftScrollCtrl,
+      middleScrollCtrl,
+      rightScrollCtrl;
 
   @override
   void initState() {
@@ -293,20 +295,20 @@ class _DatePickerState extends State<_DatePickerComponent> {
     DatePickerTheme theme = widget.route.theme;
     return GestureDetector(
       child: AnimatedBuilder(
-        animation: widget.route.animation,
-        builder: (BuildContext context, Widget child) {
+        animation: widget.route.animation!,
+        builder: (BuildContext context, Widget? child) {
           final double bottomPadding = MediaQuery.of(context).padding.bottom;
           return ClipRect(
             child: CustomSingleChildLayout(
               delegate: _BottomPickerLayout(
-                widget.route.animation.value,
+                widget.route.animation!.value,
                 theme,
-                showTitleActions: widget.route.showTitleActions,
+                showTitleActions: widget.route.showTitleActions!,
                 bottomPadding: bottomPadding,
               ),
               child: GestureDetector(
                 child: Material(
-                  color: theme.backgroundColor ?? Colors.white,
+                  color: theme.backgroundColor,
                   child: _renderPickerView(theme),
                 ),
               ),
@@ -319,13 +321,13 @@ class _DatePickerState extends State<_DatePickerComponent> {
 
   void _notifyDateChanged() {
     if (widget.onChanged != null) {
-      widget.onChanged(widget.pickerModel.finalTime());
+      widget.onChanged!(widget.pickerModel.finalTime()!);
     }
   }
 
   Widget _renderPickerView(DatePickerTheme theme) {
     Widget itemView = _renderItemView(theme);
-    if (widget.route.showTitleActions) {
+    if (widget.route.showTitleActions == true) {
       return Column(
         children: <Widget>[
           _renderTitleActionsView(theme),
@@ -350,14 +352,14 @@ class _DatePickerState extends State<_DatePickerComponent> {
       child: Container(
         padding: EdgeInsets.all(8.0),
         height: theme.containerHeight,
-        decoration: BoxDecoration(color: theme.backgroundColor ?? Colors.white),
+        decoration: BoxDecoration(color: theme.backgroundColor),
         child: NotificationListener(
           onNotification: (ScrollNotification notification) {
             if (notification.depth == 0 &&
-                selectedChangedWhenScrollEnd != null &&
                 notification is ScrollEndNotification &&
                 notification.metrics is FixedExtentMetrics) {
-              final FixedExtentMetrics metrics = notification.metrics;
+              final FixedExtentMetrics metrics =
+                  notification.metrics as FixedExtentMetrics;
               final int currentItemIndex = metrics.itemIndex;
               selectedChangedWhenScrollEnd(currentItemIndex);
             }
@@ -365,8 +367,8 @@ class _DatePickerState extends State<_DatePickerComponent> {
           },
           child: CupertinoPicker.builder(
             key: key,
-            backgroundColor: theme.backgroundColor ?? Colors.white,
-            scrollController: scrollController,
+            backgroundColor: theme.backgroundColor,
+            scrollController: scrollController as FixedExtentScrollController,
             itemExtent: theme.itemHeight,
             onSelectedItemChanged: (int index) {
               selectedChangedWhenScrolling(index);
@@ -395,7 +397,7 @@ class _DatePickerState extends State<_DatePickerComponent> {
 
   Widget _renderItemView(DatePickerTheme theme) {
     return Container(
-      color: theme.backgroundColor ?? Colors.white,
+      color: theme.backgroundColor,
       child: Row(
         mainAxisAlignment: MainAxisAlignment.spaceBetween,
         children: <Widget>[
@@ -472,7 +474,7 @@ class _DatePickerState extends State<_DatePickerComponent> {
     return Container(
       height: theme.titleHeight,
       decoration: BoxDecoration(
-        color: theme.headerColor ?? theme.backgroundColor ?? Colors.white,
+        color: theme.headerColor ?? theme.backgroundColor,
       ),
       child: Row(
         mainAxisAlignment: MainAxisAlignment.spaceBetween,
@@ -489,7 +491,7 @@ class _DatePickerState extends State<_DatePickerComponent> {
               onPressed: () {
                 Navigator.pop(context);
                 if (widget.route.onCancel != null) {
-                  widget.route.onCancel();
+                  widget.route.onCancel!();
                 }
               },
             ),
@@ -506,7 +508,7 @@ class _DatePickerState extends State<_DatePickerComponent> {
               onPressed: () {
                 Navigator.pop(context, widget.pickerModel.finalTime());
                 if (widget.route.onConfirm != null) {
-                  widget.route.onConfirm(widget.pickerModel.finalTime());
+                  widget.route.onConfirm!(widget.pickerModel.finalTime()!);
                 }
               },
             ),
@@ -517,11 +519,11 @@ class _DatePickerState extends State<_DatePickerComponent> {
   }
 
   String _localeDone() {
-    return i18nObjInLocale(widget.locale)['done'];
+    return i18nObjInLocale(widget.locale)['done'] as String;
   }
 
   String _localeCancel() {
-    return i18nObjInLocale(widget.locale)['cancel'];
+    return i18nObjInLocale(widget.locale)['cancel'] as String;
   }
 }
 
@@ -535,15 +537,15 @@ class _BottomPickerLayout extends SingleChildLayoutDelegate {
   });
 
   final double progress;
-  final int itemCount;
-  final bool showTitleActions;
+  final int? itemCount;
+  final bool? showTitleActions;
   final DatePickerTheme theme;
   final double bottomPadding;
 
   @override
   BoxConstraints getConstraintsForChild(BoxConstraints constraints) {
     double maxHeight = theme.containerHeight;
-    if (showTitleActions) {
+    if (showTitleActions == true) {
       maxHeight += theme.titleHeight;
     }
 

+ 1 - 1
lib/src/date_format.dart

@@ -227,7 +227,7 @@ String formatDate(DateTime date, List<String> formats, LocaleType locale) {
         date.month == now.month &&
         date.day == now.day) {
       //today
-      return i18nObjInLocale(locale)['today'];
+      return i18nObjInLocale(locale)['today'] as String;
     } else if (date.year == now.year) {
       if (locale == LocaleType.zh) {
         return formatDate(date, [mm, '月', dd, '日 ', D], locale);

+ 123 - 88
lib/src/date_model.dart

@@ -6,59 +6,72 @@ import 'dart:math';
 //interface for picker data model
 abstract class BasePickerModel {
   //a getter method for left column data, return null to end list
-  String leftStringAtIndex(int index);
+  String? leftStringAtIndex(int index);
+
   //a getter method for middle column data, return null to end list
-  String middleStringAtIndex(int index);
+  String? middleStringAtIndex(int index);
+
   //a getter method for right column data, return null to end list
-  String rightStringAtIndex(int index);
+  String? rightStringAtIndex(int index);
+
   //set selected left index
   void setLeftIndex(int index);
+
   //set selected middle index
   void setMiddleIndex(int index);
+
   //set selected right index
   void setRightIndex(int index);
+
   //return current left index
   int currentLeftIndex();
+
   //return current middle index
   int currentMiddleIndex();
+
   //return current right index
   int currentRightIndex();
+
   //return final time
-  DateTime finalTime();
+  DateTime? finalTime();
+
   //return left divider string
   String leftDivider();
+
   //return right divider string
   String rightDivider();
+
   //layout proportions for 3 columns
   List<int> layoutProportions();
 }
 
 //a base class for picker data model
 class CommonPickerModel extends BasePickerModel {
-  List<String> leftList;
-  List<String> middleList;
-  List<String> rightList;
-  DateTime currentTime;
-  int _currentLeftIndex;
-  int _currentMiddleIndex;
-  int _currentRightIndex;
+  late List<String> leftList;
+  late List<String> middleList;
+  late List<String> rightList;
+  late DateTime currentTime;
+  late int _currentLeftIndex;
+  late int _currentMiddleIndex;
+  late int _currentRightIndex;
 
-  LocaleType locale;
+  late LocaleType locale;
 
-  CommonPickerModel({this.currentTime, locale}) : this.locale = locale ?? LocaleType.en;
+  CommonPickerModel({LocaleType? locale})
+      : this.locale = locale ?? LocaleType.en;
 
   @override
-  String leftStringAtIndex(int index) {
+  String? leftStringAtIndex(int index) {
     return null;
   }
 
   @override
-  String middleStringAtIndex(int index) {
+  String? middleStringAtIndex(int index) {
     return null;
   }
 
   @override
-  String rightStringAtIndex(int index) {
+  String? rightStringAtIndex(int index) {
     return null;
   }
 
@@ -108,29 +121,33 @@ class CommonPickerModel extends BasePickerModel {
   }
 
   @override
-  DateTime finalTime() {
+  DateTime? finalTime() {
     return null;
   }
 }
 
 //a date picker model
 class DatePickerModel extends CommonPickerModel {
-  DateTime maxTime;
-  DateTime minTime;
-
-  DatePickerModel({DateTime currentTime, DateTime maxTime, DateTime minTime, LocaleType locale})
+  late DateTime maxTime;
+  late DateTime minTime;
+
+  DatePickerModel(
+      {DateTime? currentTime,
+      DateTime? maxTime,
+      DateTime? minTime,
+      LocaleType? locale})
       : super(locale: locale) {
     this.maxTime = maxTime ?? DateTime(2049, 12, 31);
     this.minTime = minTime ?? DateTime(1970, 1, 1);
 
     currentTime = currentTime ?? DateTime.now();
-    if (currentTime != null) {
-      if (currentTime.compareTo(this.maxTime) > 0) {
-        currentTime = this.maxTime;
-      } else if (currentTime.compareTo(this.minTime) < 0) {
-        currentTime = this.minTime;
-      }
+
+    if (currentTime.compareTo(this.maxTime) > 0) {
+      currentTime = this.maxTime;
+    } else if (currentTime.compareTo(this.minTime) < 0) {
+      currentTime = this.minTime;
     }
+
     this.currentTime = currentTime;
 
     _fillLeftLists();
@@ -160,13 +177,17 @@ class DatePickerModel extends CommonPickerModel {
 
   int _maxDayOfCurrentMonth() {
     int dayCount = calcDateCount(currentTime.year, currentTime.month);
-    return currentTime.year == maxTime.year && currentTime.month == maxTime.month
+    return currentTime.year == maxTime.year &&
+            currentTime.month == maxTime.month
         ? maxTime.day
         : dayCount;
   }
 
   int _minDayOfCurrentMonth() {
-    return currentTime.year == minTime.year && currentTime.month == minTime.month ? minTime.day : 1;
+    return currentTime.year == minTime.year &&
+            currentTime.month == minTime.month
+        ? minTime.day
+        : 1;
   }
 
   void _fillMiddleLists() {
@@ -288,7 +309,7 @@ class DatePickerModel extends CommonPickerModel {
   }
 
   @override
-  String leftStringAtIndex(int index) {
+  String? leftStringAtIndex(int index) {
     if (index >= 0 && index < leftList.length) {
       return leftList[index];
     } else {
@@ -297,7 +318,7 @@ class DatePickerModel extends CommonPickerModel {
   }
 
   @override
-  String middleStringAtIndex(int index) {
+  String? middleStringAtIndex(int index) {
     if (index >= 0 && index < middleList.length) {
       return middleList[index];
     } else {
@@ -306,7 +327,7 @@ class DatePickerModel extends CommonPickerModel {
   }
 
   @override
-  String rightStringAtIndex(int index) {
+  String? rightStringAtIndex(int index) {
     if (index >= 0 && index < rightList.length) {
       return rightList[index];
     } else {
@@ -330,7 +351,7 @@ class DatePickerModel extends CommonPickerModel {
     } else if (locale == LocaleType.ko) {
       return '$month월';
     } else {
-      List monthStrings = i18nObjInLocale(locale)['monthLong'];
+      List monthStrings = i18nObjInLocale(locale)['monthLong'] as List<String>;
       return monthStrings[month - 1];
     }
   }
@@ -355,7 +376,8 @@ class DatePickerModel extends CommonPickerModel {
 class TimePickerModel extends CommonPickerModel {
   bool showSecondsColumn;
 
-  TimePickerModel({DateTime currentTime, LocaleType locale, this.showSecondsColumn: true})
+  TimePickerModel(
+      {DateTime? currentTime, LocaleType? locale, this.showSecondsColumn: true})
       : super(locale: locale) {
     this.currentTime = currentTime ?? DateTime.now();
 
@@ -365,7 +387,7 @@ class TimePickerModel extends CommonPickerModel {
   }
 
   @override
-  String leftStringAtIndex(int index) {
+  String? leftStringAtIndex(int index) {
     if (index >= 0 && index < 24) {
       return digits(index, 2);
     } else {
@@ -374,7 +396,7 @@ class TimePickerModel extends CommonPickerModel {
   }
 
   @override
-  String middleStringAtIndex(int index) {
+  String? middleStringAtIndex(int index) {
     if (index >= 0 && index < 60) {
       return digits(index, 2);
     } else {
@@ -383,7 +405,7 @@ class TimePickerModel extends CommonPickerModel {
   }
 
   @override
-  String rightStringAtIndex(int index) {
+  String? rightStringAtIndex(int index) {
     if (index >= 0 && index < 60) {
       return digits(index, 2);
     } else {
@@ -415,16 +437,17 @@ class TimePickerModel extends CommonPickerModel {
   @override
   DateTime finalTime() {
     return currentTime.isUtc
-        ? DateTime.utc(currentTime.year, currentTime.month, currentTime.day, _currentLeftIndex,
-            _currentMiddleIndex, _currentRightIndex)
-        : DateTime(currentTime.year, currentTime.month, currentTime.day, _currentLeftIndex,
-            _currentMiddleIndex, _currentRightIndex);
+        ? DateTime.utc(currentTime.year, currentTime.month, currentTime.day,
+            _currentLeftIndex, _currentMiddleIndex, _currentRightIndex)
+        : DateTime(currentTime.year, currentTime.month, currentTime.day,
+            _currentLeftIndex, _currentMiddleIndex, _currentRightIndex);
   }
 }
 
 //a time picker model
 class Time12hPickerModel extends CommonPickerModel {
-  Time12hPickerModel({DateTime currentTime, LocaleType locale}) : super(locale: locale) {
+  Time12hPickerModel({DateTime? currentTime, LocaleType? locale})
+      : super(locale: locale) {
     this.currentTime = currentTime ?? DateTime.now();
 
     _currentLeftIndex = this.currentTime.hour % 12;
@@ -433,7 +456,7 @@ class Time12hPickerModel extends CommonPickerModel {
   }
 
   @override
-  String leftStringAtIndex(int index) {
+  String? leftStringAtIndex(int index) {
     if (index >= 0 && index < 12) {
       if (index == 0) {
         return digits(12, 2);
@@ -446,7 +469,7 @@ class Time12hPickerModel extends CommonPickerModel {
   }
 
   @override
-  String middleStringAtIndex(int index) {
+  String? middleStringAtIndex(int index) {
     if (index >= 0 && index < 60) {
       return digits(index, 2);
     } else {
@@ -455,11 +478,11 @@ class Time12hPickerModel extends CommonPickerModel {
   }
 
   @override
-  String rightStringAtIndex(int index) {
+  String? rightStringAtIndex(int index) {
     if (index == 0) {
-      return  i18nObjInLocale(this.locale)["am"];
+      return i18nObjInLocale(this.locale)["am"] as String?;
     } else if (index == 1) {
-      return i18nObjInLocale(this.locale)["pm"];
+      return i18nObjInLocale(this.locale)["pm"] as String?;
     } else {
       return null;
     }
@@ -484,43 +507,52 @@ class Time12hPickerModel extends CommonPickerModel {
   DateTime finalTime() {
     int hour = _currentLeftIndex + 12 * _currentRightIndex;
     return currentTime.isUtc
-        ? DateTime.utc(
-            currentTime.year, currentTime.month, currentTime.day, hour, _currentMiddleIndex, 0)
-        : DateTime(
-            currentTime.year, currentTime.month, currentTime.day, hour, _currentMiddleIndex, 0);
+        ? DateTime.utc(currentTime.year, currentTime.month, currentTime.day,
+            hour, _currentMiddleIndex, 0)
+        : DateTime(currentTime.year, currentTime.month, currentTime.day, hour,
+            _currentMiddleIndex, 0);
   }
 }
 
 // a date&time picker model
 class DateTimePickerModel extends CommonPickerModel {
-  DateTime maxTime;
-  DateTime minTime;
-  DateTimePickerModel({DateTime currentTime, DateTime maxTime, DateTime minTime, LocaleType locale})
+  DateTime? maxTime;
+  DateTime? minTime;
+
+  DateTimePickerModel(
+      {DateTime? currentTime,
+      DateTime? maxTime,
+      DateTime? minTime,
+      LocaleType? locale})
       : super(locale: locale) {
     if (currentTime != null) {
       this.currentTime = currentTime;
       if (maxTime != null &&
-          (currentTime.isBefore(maxTime) || currentTime.isAtSameMomentAs(maxTime))) {
+          (currentTime.isBefore(maxTime) ||
+              currentTime.isAtSameMomentAs(maxTime))) {
         this.maxTime = maxTime;
       }
       if (minTime != null &&
-          (currentTime.isAfter(minTime) || currentTime.isAtSameMomentAs(minTime))) {
+          (currentTime.isAfter(minTime) ||
+              currentTime.isAtSameMomentAs(minTime))) {
         this.minTime = minTime;
       }
     } else {
       this.maxTime = maxTime;
       this.minTime = minTime;
       var now = DateTime.now();
-      if (this.minTime != null && this.minTime.isAfter(now)) {
-        this.currentTime = this.minTime;
-      } else if (this.maxTime != null && this.maxTime.isBefore(now)) {
-        this.currentTime = this.maxTime;
+      if (this.minTime != null && this.minTime!.isAfter(now)) {
+        this.currentTime = this.minTime!;
+      } else if (this.maxTime != null && this.maxTime!.isBefore(now)) {
+        this.currentTime = this.maxTime!;
       } else {
         this.currentTime = now;
       }
     }
 
-    if (this.minTime != null && this.maxTime != null && this.maxTime.isBefore(this.minTime)) {
+    if (this.minTime != null &&
+        this.maxTime != null &&
+        this.maxTime!.isBefore(this.minTime!)) {
       // invalid
       this.minTime = null;
       this.maxTime = null;
@@ -529,15 +561,15 @@ class DateTimePickerModel extends CommonPickerModel {
     _currentLeftIndex = 0;
     _currentMiddleIndex = this.currentTime.hour;
     _currentRightIndex = this.currentTime.minute;
-    if (this.minTime != null && isAtSameDay(this.minTime, this.currentTime)) {
-      _currentMiddleIndex = this.currentTime.hour - this.minTime.hour;
+    if (this.minTime != null && isAtSameDay(this.minTime!, this.currentTime)) {
+      _currentMiddleIndex = this.currentTime.hour - this.minTime!.hour;
       if (_currentMiddleIndex == 0) {
-        _currentRightIndex = this.currentTime.minute - this.minTime.minute;
+        _currentRightIndex = this.currentTime.minute - this.minTime!.minute;
       }
     }
   }
 
-  bool isAtSameDay(DateTime day1, DateTime day2) {
+  bool isAtSameDay(DateTime? day1, DateTime? day2) {
     return day1 != null &&
         day2 != null &&
         day1.difference(day2).inDays == 0 &&
@@ -546,31 +578,29 @@ class DateTimePickerModel extends CommonPickerModel {
 
   @override
   void setLeftIndex(int index) {
-    // TODO: implement setLeftIndex
     super.setLeftIndex(index);
-
     DateTime time = currentTime.add(Duration(days: index));
     if (isAtSameDay(minTime, time)) {
-      var index = min(24 - minTime.hour - 1, _currentMiddleIndex);
+      var index = min(24 - minTime!.hour - 1, _currentMiddleIndex);
       this.setMiddleIndex(index);
     } else if (isAtSameDay(maxTime, time)) {
-      var index = min(maxTime.hour, _currentMiddleIndex);
+      var index = min(maxTime!.hour, _currentMiddleIndex);
       this.setMiddleIndex(index);
     }
   }
 
   @override
   void setMiddleIndex(int index) {
-    // TODO: implement setMiddleIndex
     super.setMiddleIndex(index);
     DateTime time = currentTime.add(Duration(days: _currentLeftIndex));
     if (isAtSameDay(minTime, time) && index == 0) {
-      var maxIndex = 60 - minTime.minute - 1;
+      var maxIndex = 60 - minTime!.minute - 1;
       if (_currentRightIndex > maxIndex) {
         _currentRightIndex = maxIndex;
       }
-    } else if (isAtSameDay(maxTime, time) && _currentMiddleIndex == maxTime.hour) {
-      var maxIndex = maxTime.minute;
+    } else if (isAtSameDay(maxTime, time) &&
+        _currentMiddleIndex == maxTime!.hour) {
+      var maxIndex = maxTime!.minute;
       if (_currentRightIndex > maxIndex) {
         _currentRightIndex = maxIndex;
       }
@@ -578,28 +608,32 @@ class DateTimePickerModel extends CommonPickerModel {
   }
 
   @override
-  String leftStringAtIndex(int index) {
+  String? leftStringAtIndex(int index) {
     DateTime time = currentTime.add(Duration(days: index));
-    if (minTime != null && time.isBefore(minTime) && !isAtSameDay(minTime, time)) {
+    if (minTime != null &&
+        time.isBefore(minTime!) &&
+        !isAtSameDay(minTime!, time)) {
       return null;
-    } else if (maxTime != null && time.isAfter(maxTime) && !isAtSameDay(maxTime, time)) {
+    } else if (maxTime != null &&
+        time.isAfter(maxTime!) &&
+        !isAtSameDay(maxTime, time)) {
       return null;
     }
     return formatDate(time, [ymdw], locale);
   }
 
   @override
-  String middleStringAtIndex(int index) {
+  String? middleStringAtIndex(int index) {
     if (index >= 0 && index < 24) {
       DateTime time = currentTime.add(Duration(days: _currentLeftIndex));
       if (isAtSameDay(minTime, time)) {
-        if (index >= 0 && index < 24 - minTime.hour) {
-          return digits(minTime.hour + index, 2);
+        if (index >= 0 && index < 24 - minTime!.hour) {
+          return digits(minTime!.hour + index, 2);
         } else {
           return null;
         }
       } else if (isAtSameDay(maxTime, time)) {
-        if (index >= 0 && index <= maxTime.hour) {
+        if (index >= 0 && index <= maxTime!.hour) {
           return digits(index, 2);
         } else {
           return null;
@@ -612,17 +646,18 @@ class DateTimePickerModel extends CommonPickerModel {
   }
 
   @override
-  String rightStringAtIndex(int index) {
+  String? rightStringAtIndex(int index) {
     if (index >= 0 && index < 60) {
       DateTime time = currentTime.add(Duration(days: _currentLeftIndex));
       if (isAtSameDay(minTime, time) && _currentMiddleIndex == 0) {
-        if (index >= 0 && index < 60 - minTime.minute) {
-          return digits(minTime.minute + index, 2);
+        if (index >= 0 && index < 60 - minTime!.minute) {
+          return digits(minTime!.minute + index, 2);
         } else {
           return null;
         }
-      } else if (isAtSameDay(maxTime, time) && _currentMiddleIndex >= maxTime.hour) {
-        if (index >= 0 && index <= maxTime.minute) {
+      } else if (isAtSameDay(maxTime, time) &&
+          _currentMiddleIndex >= maxTime!.hour) {
+        if (index >= 0 && index <= maxTime!.minute) {
           return digits(index, 2);
         } else {
           return null;
@@ -640,9 +675,9 @@ class DateTimePickerModel extends CommonPickerModel {
     var hour = _currentMiddleIndex;
     var minute = _currentRightIndex;
     if (isAtSameDay(minTime, time)) {
-      hour += minTime.hour;
-      if (minTime.hour == hour) {
-        minute += minTime.minute;
+      hour += minTime!.hour;
+      if (minTime!.hour == hour) {
+        minute += minTime!.minute;
       }
     }
 

+ 1 - 1
lib/src/datetime_picker_theme.dart

@@ -8,7 +8,7 @@ class DatePickerTheme with DiagnosticableTreeMixin {
   final TextStyle doneStyle;
   final TextStyle itemStyle;
   final Color backgroundColor;
-  final Color headerColor;
+  final Color? headerColor;
 
   final double containerHeight;
   final double titleHeight;

+ 2 - 2
lib/src/i18n_model.dart

@@ -1307,8 +1307,8 @@ final _i18nModel = <LocaleType, Map<String, Object>>{
 };
 
 /// Get international object for [localeType]
-Map<String, Object> i18nObjInLocale(LocaleType localeType) =>
-    _i18nModel[localeType] ?? _i18nModel[LocaleType.en];
+Map<String, Object> i18nObjInLocale(LocaleType? localeType) =>
+    _i18nModel[localeType] ?? _i18nModel[LocaleType.en] as Map<String, Object>;
 
 /// Get international lookup for a [localeType], [key] and [index].
 String i18nObjInLocaleLookup(LocaleType localeType, String key, int index) {

+ 1 - 1
pubspec.yaml

@@ -4,7 +4,7 @@ version: 1.4.0
 homepage: https://github.com/Realank/flutter_datetime_picker
 
 environment:
-  sdk: ">=2.0.0 <3.0.0"
+  sdk: ">=2.12.0 <3.0.0"
 
 dependencies:
   flutter: