|
|
@@ -1,10 +1,11 @@
|
|
|
library flutter_datetime_picker;
|
|
|
|
|
|
-export 'package:flutter_datetime_picker/src/dateModel.dart';
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:flutter_datetime_picker/src/dateModel.dart';
|
|
|
|
|
|
+export 'package:flutter_datetime_picker/src/dateModel.dart';
|
|
|
+
|
|
|
typedef DateChangedCallback(DateTime time);
|
|
|
typedef String StringAtIndexCallBack(int index);
|
|
|
|
|
|
@@ -31,8 +32,10 @@ class DatePicker {
|
|
|
onConfirm: onConfirm,
|
|
|
locale: locale,
|
|
|
theme: Theme.of(context, shadowThemeOnly: true),
|
|
|
- barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
|
|
|
- pickerModel: DatePickerModel(currentTime: currentTime, locale: locale)));
|
|
|
+ barrierLabel:
|
|
|
+ MaterialLocalizations.of(context).modalBarrierDismissLabel,
|
|
|
+ pickerModel:
|
|
|
+ DatePickerModel(currentTime: currentTime, locale: locale)));
|
|
|
}
|
|
|
|
|
|
///
|
|
|
@@ -52,8 +55,10 @@ class DatePicker {
|
|
|
onConfirm: onConfirm,
|
|
|
locale: locale,
|
|
|
theme: Theme.of(context, shadowThemeOnly: true),
|
|
|
- barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
|
|
|
- pickerModel: TimePickerModel(currentTime: currentTime, locale: locale)));
|
|
|
+ barrierLabel:
|
|
|
+ MaterialLocalizations.of(context).modalBarrierDismissLabel,
|
|
|
+ pickerModel:
|
|
|
+ TimePickerModel(currentTime: currentTime, locale: locale)));
|
|
|
}
|
|
|
|
|
|
///
|
|
|
@@ -73,8 +78,10 @@ class DatePicker {
|
|
|
onConfirm: onConfirm,
|
|
|
locale: locale,
|
|
|
theme: Theme.of(context, shadowThemeOnly: true),
|
|
|
- barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
|
|
|
- pickerModel: DateTimePickerModel(currentTime: currentTime, locale: locale)));
|
|
|
+ barrierLabel:
|
|
|
+ MaterialLocalizations.of(context).modalBarrierDismissLabel,
|
|
|
+ pickerModel:
|
|
|
+ DateTimePickerModel(currentTime: currentTime, locale: locale)));
|
|
|
}
|
|
|
|
|
|
///
|
|
|
@@ -94,7 +101,8 @@ class DatePicker {
|
|
|
onConfirm: onConfirm,
|
|
|
locale: locale,
|
|
|
theme: Theme.of(context, shadowThemeOnly: true),
|
|
|
- barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
|
|
|
+ barrierLabel:
|
|
|
+ MaterialLocalizations.of(context).modalBarrierDismissLabel,
|
|
|
pickerModel: pickerModel));
|
|
|
}
|
|
|
}
|
|
|
@@ -136,13 +144,14 @@ class _DatePickerRoute<T> extends PopupRoute<T> {
|
|
|
@override
|
|
|
AnimationController createAnimationController() {
|
|
|
assert(_animationController == null);
|
|
|
- _animationController = BottomSheet.createAnimationController(navigator.overlay);
|
|
|
+ _animationController =
|
|
|
+ BottomSheet.createAnimationController(navigator.overlay);
|
|
|
return _animationController;
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
- Widget buildPage(
|
|
|
- BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
|
|
|
+ Widget buildPage(BuildContext context, Animation<double> animation,
|
|
|
+ Animation<double> secondaryAnimation) {
|
|
|
Widget bottomSheet = new MediaQuery.removePadding(
|
|
|
context: context,
|
|
|
removeTop: true,
|
|
|
@@ -162,7 +171,11 @@ class _DatePickerRoute<T> extends PopupRoute<T> {
|
|
|
|
|
|
class _DatePickerComponent extends StatefulWidget {
|
|
|
_DatePickerComponent(
|
|
|
- {Key key, @required this.route, this.onChanged, this.locale, this.pickerModel});
|
|
|
+ {Key key,
|
|
|
+ @required this.route,
|
|
|
+ this.onChanged,
|
|
|
+ this.locale,
|
|
|
+ this.pickerModel});
|
|
|
|
|
|
final DateChangedCallback onChanged;
|
|
|
|
|
|
@@ -188,12 +201,12 @@ class _DatePickerState extends State<_DatePickerComponent> {
|
|
|
}
|
|
|
|
|
|
void refreshScrollOffset() {
|
|
|
- leftScrollCtrl =
|
|
|
- new FixedExtentScrollController(initialItem: widget.pickerModel.currentLeftIndex());
|
|
|
- middleScrollCtrl =
|
|
|
- new FixedExtentScrollController(initialItem: widget.pickerModel.currentMiddleIndex());
|
|
|
- rightScrollCtrl =
|
|
|
- new FixedExtentScrollController(initialItem: widget.pickerModel.currentRightIndex());
|
|
|
+ leftScrollCtrl = new FixedExtentScrollController(
|
|
|
+ initialItem: widget.pickerModel.currentLeftIndex());
|
|
|
+ middleScrollCtrl = new FixedExtentScrollController(
|
|
|
+ initialItem: widget.pickerModel.currentMiddleIndex());
|
|
|
+ rightScrollCtrl = new FixedExtentScrollController(
|
|
|
+ initialItem: widget.pickerModel.currentRightIndex());
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
@@ -281,7 +294,9 @@ class _DatePickerState extends State<_DatePickerComponent> {
|
|
|
alignment: Alignment.center,
|
|
|
child: Text(
|
|
|
content,
|
|
|
- style: TextStyle(color: Color(0xFF000046), fontSize: _kDatePickerFontSize),
|
|
|
+ style: TextStyle(
|
|
|
+ color: Color(0xFF000046),
|
|
|
+ fontSize: _kDatePickerFontSize),
|
|
|
textAlign: TextAlign.start,
|
|
|
),
|
|
|
);
|
|
|
@@ -295,16 +310,21 @@ class _DatePickerState extends State<_DatePickerComponent> {
|
|
|
child: Row(
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
children: <Widget>[
|
|
|
- _renderColumnView(widget.pickerModel.leftStringAtIndex, leftScrollCtrl,
|
|
|
+ _renderColumnView(
|
|
|
+ widget.pickerModel.leftStringAtIndex,
|
|
|
+ leftScrollCtrl,
|
|
|
widget.pickerModel.layoutProportions()[0], (index) {
|
|
|
widget.pickerModel.setLeftIndex(index);
|
|
|
_notifyDateChanged();
|
|
|
}, null),
|
|
|
Text(
|
|
|
widget.pickerModel.leftDivider(),
|
|
|
- style: TextStyle(color: Color(0xFF000046), fontSize: _kDatePickerFontSize),
|
|
|
+ style: TextStyle(
|
|
|
+ color: Color(0xFF000046), fontSize: _kDatePickerFontSize),
|
|
|
),
|
|
|
- _renderColumnView(widget.pickerModel.middleStringAtIndex, middleScrollCtrl,
|
|
|
+ _renderColumnView(
|
|
|
+ widget.pickerModel.middleStringAtIndex,
|
|
|
+ middleScrollCtrl,
|
|
|
widget.pickerModel.layoutProportions()[1], (index) {
|
|
|
widget.pickerModel.setMiddleIndex(index);
|
|
|
}, (index) {
|
|
|
@@ -314,9 +334,12 @@ class _DatePickerState extends State<_DatePickerComponent> {
|
|
|
}),
|
|
|
Text(
|
|
|
widget.pickerModel.rightDivider(),
|
|
|
- style: TextStyle(color: Color(0xFF000046), fontSize: _kDatePickerFontSize),
|
|
|
+ style: TextStyle(
|
|
|
+ color: Color(0xFF000046), fontSize: _kDatePickerFontSize),
|
|
|
),
|
|
|
- _renderColumnView(widget.pickerModel.rightStringAtIndex, rightScrollCtrl,
|
|
|
+ _renderColumnView(
|
|
|
+ widget.pickerModel.rightStringAtIndex,
|
|
|
+ rightScrollCtrl,
|
|
|
widget.pickerModel.layoutProportions()[2], (index) {
|
|
|
widget.pickerModel.setRightIndex(index);
|
|
|
_notifyDateChanged();
|
|
|
@@ -374,18 +397,22 @@ class _DatePickerState extends State<_DatePickerComponent> {
|
|
|
}
|
|
|
|
|
|
String _localeDone() {
|
|
|
- if (widget.locale.matchAsPrefix('cn') == null) {
|
|
|
- return 'Done';
|
|
|
- } else {
|
|
|
+ if (widget.locale.matchAsPrefix('cn') != null) {
|
|
|
return '确定';
|
|
|
+ } else if (widget.locale.matchAsPrefix('nl') != null) {
|
|
|
+ return 'Klaar';
|
|
|
+ } else {
|
|
|
+ return 'Done';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
String _localeCancel() {
|
|
|
- if (widget.locale.matchAsPrefix('cn') == null) {
|
|
|
- return 'Cancel';
|
|
|
- } else {
|
|
|
+ if (widget.locale.matchAsPrefix('cn') != null) {
|
|
|
return '取消';
|
|
|
+ } else if (widget.locale.matchAsPrefix('nl') != null) {
|
|
|
+ return 'Annuleer';
|
|
|
+ } else {
|
|
|
+ return 'Cancel';
|
|
|
}
|
|
|
}
|
|
|
}
|