diff --git a/README.md b/README.md
index 325de9b9..9b9eacf0 100644
--- a/README.md
+++ b/README.md
@@ -57,7 +57,7 @@ International:
## Usage
```
-FlatButton(
+TextButton(
onPressed: () {
DatePicker.showDatePicker(context,
showTitleActions: true,
diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml
index eb3d7156..421ac63d 100644
--- a/example/android/app/src/main/AndroidManifest.xml
+++ b/example/android/app/src/main/AndroidManifest.xml
@@ -13,7 +13,6 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
-
+
+
+ android:name="io.flutter.embedding.android.SplashScreenDrawable"
+ android:resource="@drawable/launch_background" />
+
+
+
+
+
+
+
diff --git a/example/android/app/src/main/java/com/realank/example/MainActivity.java b/example/android/app/src/main/java/com/realank/example/MainActivity.java
index f0a7e5df..de50d78f 100644
--- a/example/android/app/src/main/java/com/realank/example/MainActivity.java
+++ b/example/android/app/src/main/java/com/realank/example/MainActivity.java
@@ -1,13 +1,4 @@
package com.realank.example;
+import io.flutter.embedding.android.FlutterActivity;
-import android.os.Bundle;
-import io.flutter.app.FlutterActivity;
-import io.flutter.plugins.GeneratedPluginRegistrant;
-
-public class MainActivity extends FlutterActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- GeneratedPluginRegistrant.registerWith(this);
- }
-}
+public class MainActivity extends FlutterActivity {}
diff --git a/example/android/app/src/main/res/values/styles.xml b/example/android/app/src/main/res/values/styles.xml
index 00fa4417..f09400a8 100644
--- a/example/android/app/src/main/res/values/styles.xml
+++ b/example/android/app/src/main/res/values/styles.xml
@@ -5,4 +5,8 @@
Flutter draws its first frame -->
- @drawable/launch_background
+
+
diff --git a/example/ios/.gitignore b/example/ios/.gitignore
index 79cc4da8..c096a2d4 100644
--- a/example/ios/.gitignore
+++ b/example/ios/.gitignore
@@ -40,6 +40,7 @@ Icon?
/Flutter/Flutter.framework
/Flutter/Generated.xcconfig
/ServiceDefinitions.json
+/Flutter/flutter_export_environment.sh
Pods/
.symlinks/
diff --git a/example/lib/main.dart b/example/lib/main.dart
index c5c12362..1ab0e793 100644
--- a/example/lib/main.dart
+++ b/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());
}
}
@@ -91,7 +102,7 @@ class HomePage extends StatelessWidget {
body: Center(
child: Column(
children: [
- FlatButton(
+ TextButton(
onPressed: () {
DatePicker.showDatePicker(context,
showTitleActions: true,
@@ -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);
@@ -113,10 +128,12 @@ class HomePage extends StatelessWidget {
'show date picker(custom theme &date time range)',
style: TextStyle(color: Colors.blue),
)),
- FlatButton(
+ 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());
@@ -125,10 +142,12 @@ class HomePage extends StatelessWidget {
'show time picker',
style: TextStyle(color: Colors.blue),
)),
- FlatButton(
+ 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());
@@ -137,13 +156,14 @@ class HomePage extends StatelessWidget {
'show 12H time picker with AM/PM',
style: TextStyle(color: Colors.blue),
)),
- FlatButton(
+ TextButton(
onPressed: () {
DatePicker.showDateTimePicker(context,
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);
@@ -152,10 +172,12 @@ class HomePage extends StatelessWidget {
'show date time picker (Chinese)',
style: TextStyle(color: Colors.blue),
)),
- FlatButton(
+ 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));
@@ -164,49 +186,65 @@ class HomePage extends StatelessWidget {
'show date time picker (English-America)',
style: TextStyle(color: Colors.blue),
)),
- FlatButton(
+ 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)',
style: TextStyle(color: Colors.blue),
)),
- FlatButton(
+ 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)',
style: TextStyle(color: Colors.blue),
)),
- FlatButton(
+ 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)',
style: TextStyle(color: Colors.blue),
)),
- FlatButton(
+ 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',
diff --git a/example/pubspec.yaml b/example/pubspec.yaml
index 6914dd16..ecbd1058 100644
--- a/example/pubspec.yaml
+++ b/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: ../
diff --git a/lib/flutter_datetime_picker.dart b/lib/flutter_datetime_picker.dart
index 572c47dd..5e1073ac 100644
--- a/lib/flutter_datetime_picker.dart
+++ b/lib/flutter_datetime_picker.dart
@@ -13,23 +13,23 @@ 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 {
///
/// Display date picker bottom sheet.
///
- static Future showDatePicker(
+ static Future 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,
@@ -55,16 +55,16 @@ class DatePicker {
///
/// Display time picker bottom sheet.
///
- static Future showTimePicker(
+ static Future showTimePicker(
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,
@@ -89,15 +89,15 @@ class DatePicker {
///
/// Display time picker bottom sheet with AM/PM.
///
- static Future showTime12hPicker(
+ static Future 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,
@@ -121,17 +121,17 @@ class DatePicker {
///
/// Display date&time picker bottom sheet.
///
- static Future showDateTimePicker(
+ static Future 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,
@@ -157,15 +157,15 @@ class DatePicker {
///
/// Display date picker bottom sheet witch custom picker model.
///
- static Future showPicker(
+ static Future 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 extends PopupRoute {
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 extends PopupRoute {
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 extends PopupRoute {
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: [
_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: [
@@ -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;
}
diff --git a/lib/src/date_format.dart b/lib/src/date_format.dart
index c71ad42c..583fb1af 100755
--- a/lib/src/date_format.dart
+++ b/lib/src/date_format.dart
@@ -227,7 +227,7 @@ String formatDate(DateTime date, List 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);
diff --git a/lib/src/date_model.dart b/lib/src/date_model.dart
index 7f22b746..0e899870 100644
--- a/lib/src/date_model.dart
+++ b/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 layoutProportions();
}
//a base class for picker data model
class CommonPickerModel extends BasePickerModel {
- List leftList;
- List middleList;
- List rightList;
- DateTime currentTime;
- int _currentLeftIndex;
- int _currentMiddleIndex;
- int _currentRightIndex;
+ late List leftList;
+ late List middleList;
+ late List 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;
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;
}
}
diff --git a/lib/src/datetime_picker_theme.dart b/lib/src/datetime_picker_theme.dart
index f98e2752..e3f616f4 100644
--- a/lib/src/datetime_picker_theme.dart
+++ b/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;
diff --git a/lib/src/i18n_model.dart b/lib/src/i18n_model.dart
index 248de956..76d8f9fb 100644
--- a/lib/src/i18n_model.dart
+++ b/lib/src/i18n_model.dart
@@ -1307,8 +1307,8 @@ final _i18nModel = >{
};
/// Get international object for [localeType]
-Map i18nObjInLocale(LocaleType localeType) =>
- _i18nModel[localeType] ?? _i18nModel[LocaleType.en];
+Map i18nObjInLocale(LocaleType? localeType) =>
+ _i18nModel[localeType] ?? _i18nModel[LocaleType.en] as Map;
/// Get international lookup for a [localeType], [key] and [index].
String i18nObjInLocaleLookup(LocaleType localeType, String key, int index) {
diff --git a/pubspec.yaml b/pubspec.yaml
index f0555cce..67a7799f 100644
--- a/pubspec.yaml
+++ b/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: