|
@@ -20,8 +20,8 @@ class DatePicker {
|
|
|
static void showDatePicker(
|
|
static void showDatePicker(
|
|
|
BuildContext context, {
|
|
BuildContext context, {
|
|
|
bool showTitleActions: true,
|
|
bool showTitleActions: true,
|
|
|
- DateTime min,
|
|
|
|
|
- DateTime max,
|
|
|
|
|
|
|
+ DateTime minTime,
|
|
|
|
|
+ DateTime maxTime,
|
|
|
DateChangedCallback onChanged,
|
|
DateChangedCallback onChanged,
|
|
|
DateChangedCallback onConfirm,
|
|
DateChangedCallback onConfirm,
|
|
|
locale: LocaleType.en,
|
|
locale: LocaleType.en,
|
|
@@ -37,7 +37,8 @@ class DatePicker {
|
|
|
locale: locale,
|
|
locale: locale,
|
|
|
theme: theme,
|
|
theme: theme,
|
|
|
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
|
|
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
|
|
|
- pickerModel: DatePickerModel(currentTime: currentTime, max: max, min: min, locale: locale)));
|
|
|
|
|
|
|
+ pickerModel: DatePickerModel(
|
|
|
|
|
+ currentTime: currentTime, maxTime: maxTime, minTime: minTime, locale: locale)));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
///
|
|
///
|
|
@@ -46,8 +47,6 @@ class DatePicker {
|
|
|
static void showTimePicker(
|
|
static void showTimePicker(
|
|
|
BuildContext context, {
|
|
BuildContext context, {
|
|
|
bool showTitleActions: true,
|
|
bool showTitleActions: true,
|
|
|
- DateTime min,
|
|
|
|
|
- DateTime max,
|
|
|
|
|
DateChangedCallback onChanged,
|
|
DateChangedCallback onChanged,
|
|
|
DateChangedCallback onConfirm,
|
|
DateChangedCallback onConfirm,
|
|
|
locale: LocaleType.en,
|
|
locale: LocaleType.en,
|
|
@@ -63,7 +62,7 @@ class DatePicker {
|
|
|
locale: locale,
|
|
locale: locale,
|
|
|
theme: theme,
|
|
theme: theme,
|
|
|
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
|
|
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
|
|
|
- pickerModel: TimePickerModel(currentTime: currentTime, max: max, min: min, locale: locale)));
|
|
|
|
|
|
|
+ pickerModel: TimePickerModel(currentTime: currentTime, locale: locale)));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
///
|
|
///
|
|
@@ -122,12 +121,13 @@ class _DatePickerRoute<T> extends PopupRoute<T> {
|
|
|
this.showTitleActions,
|
|
this.showTitleActions,
|
|
|
this.onChanged,
|
|
this.onChanged,
|
|
|
this.onConfirm,
|
|
this.onConfirm,
|
|
|
- this.theme,
|
|
|
|
|
|
|
+ theme,
|
|
|
this.barrierLabel,
|
|
this.barrierLabel,
|
|
|
this.locale,
|
|
this.locale,
|
|
|
RouteSettings settings,
|
|
RouteSettings settings,
|
|
|
pickerModel,
|
|
pickerModel,
|
|
|
}) : this.pickerModel = pickerModel ?? DatePickerModel(),
|
|
}) : this.pickerModel = pickerModel ?? DatePickerModel(),
|
|
|
|
|
+ this.theme = theme ?? DatePickerTheme(),
|
|
|
super(settings: settings);
|
|
super(settings: settings);
|
|
|
|
|
|
|
|
final bool showTitleActions;
|
|
final bool showTitleActions;
|
|
@@ -147,7 +147,7 @@ class _DatePickerRoute<T> extends PopupRoute<T> {
|
|
|
final String barrierLabel;
|
|
final String barrierLabel;
|
|
|
|
|
|
|
|
@override
|
|
@override
|
|
|
- Color get barrierColor => theme?.barrierColor ?? Colors.black54;
|
|
|
|
|
|
|
+ Color get barrierColor => Colors.black54;
|
|
|
|
|
|
|
|
AnimationController _animationController;
|
|
AnimationController _animationController;
|
|
|
|
|
|
|
@@ -159,7 +159,8 @@ class _DatePickerRoute<T> extends PopupRoute<T> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
@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(
|
|
Widget bottomSheet = new MediaQuery.removePadding(
|
|
|
context: context,
|
|
context: context,
|
|
|
removeTop: true,
|
|
removeTop: true,
|
|
@@ -170,15 +171,17 @@ class _DatePickerRoute<T> extends PopupRoute<T> {
|
|
|
pickerModel: pickerModel,
|
|
pickerModel: pickerModel,
|
|
|
),
|
|
),
|
|
|
);
|
|
);
|
|
|
- if (theme != null) {
|
|
|
|
|
- bottomSheet = new Theme(data: Theme.of(context, shadowThemeOnly: true), child: bottomSheet);
|
|
|
|
|
|
|
+ ThemeData inheritTheme = Theme.of(context, shadowThemeOnly: true);
|
|
|
|
|
+ if (inheritTheme != null) {
|
|
|
|
|
+ bottomSheet = new Theme(data: inheritTheme, child: bottomSheet);
|
|
|
}
|
|
}
|
|
|
return bottomSheet;
|
|
return bottomSheet;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
class _DatePickerComponent extends StatefulWidget {
|
|
class _DatePickerComponent extends StatefulWidget {
|
|
|
- _DatePickerComponent({Key key, @required this.route, this.onChanged, this.locale, this.pickerModel});
|
|
|
|
|
|
|
+ _DatePickerComponent(
|
|
|
|
|
+ {Key key, @required this.route, this.onChanged, this.locale, this.pickerModel});
|
|
|
|
|
|
|
|
final DateChangedCallback onChanged;
|
|
final DateChangedCallback onChanged;
|
|
|
|
|
|
|
@@ -204,24 +207,25 @@ class _DatePickerState extends State<_DatePickerComponent> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void refreshScrollOffset() {
|
|
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
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
Widget build(BuildContext context) {
|
|
|
- DatePickerTheme theme = DefaultDatePickerTheme.of(context).theme;
|
|
|
|
|
- if (widget.route.theme != null) {
|
|
|
|
|
- theme = widget.route.theme.merge(theme);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ DatePickerTheme theme = widget.route.theme;
|
|
|
return new GestureDetector(
|
|
return new GestureDetector(
|
|
|
child: new AnimatedBuilder(
|
|
child: new AnimatedBuilder(
|
|
|
animation: widget.route.animation,
|
|
animation: widget.route.animation,
|
|
|
builder: (BuildContext context, Widget child) {
|
|
builder: (BuildContext context, Widget child) {
|
|
|
return new ClipRect(
|
|
return new ClipRect(
|
|
|
child: new CustomSingleChildLayout(
|
|
child: new CustomSingleChildLayout(
|
|
|
- delegate: new _BottomPickerLayout(widget.route.animation.value, theme, showTitleActions: widget.route.showTitleActions),
|
|
|
|
|
|
|
+ delegate: new _BottomPickerLayout(widget.route.animation.value, theme,
|
|
|
|
|
+ showTitleActions: widget.route.showTitleActions),
|
|
|
child: new GestureDetector(
|
|
child: new GestureDetector(
|
|
|
child: Material(
|
|
child: Material(
|
|
|
color: Colors.transparent,
|
|
color: Colors.transparent,
|
|
@@ -254,14 +258,20 @@ class _DatePickerState extends State<_DatePickerComponent> {
|
|
|
return itemView;
|
|
return itemView;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Widget _renderColumnView(ValueKey key, DatePickerTheme theme, StringAtIndexCallBack stringAtIndexCB, ScrollController scrollController, int layoutProportion,
|
|
|
|
|
- ValueChanged<int> selectedChangedWhenScrolling, ValueChanged<int> selectedChangedWhenScrollEnd) {
|
|
|
|
|
|
|
+ Widget _renderColumnView(
|
|
|
|
|
+ ValueKey key,
|
|
|
|
|
+ DatePickerTheme theme,
|
|
|
|
|
+ StringAtIndexCallBack stringAtIndexCB,
|
|
|
|
|
+ ScrollController scrollController,
|
|
|
|
|
+ int layoutProportion,
|
|
|
|
|
+ ValueChanged<int> selectedChangedWhenScrolling,
|
|
|
|
|
+ ValueChanged<int> selectedChangedWhenScrollEnd) {
|
|
|
return Expanded(
|
|
return Expanded(
|
|
|
flex: layoutProportion,
|
|
flex: layoutProportion,
|
|
|
child: Container(
|
|
child: Container(
|
|
|
padding: EdgeInsets.all(8.0),
|
|
padding: EdgeInsets.all(8.0),
|
|
|
height: theme.containerHeight,
|
|
height: theme.containerHeight,
|
|
|
- decoration: BoxDecoration(color: theme?.backgroundColor ?? Colors.white),
|
|
|
|
|
|
|
+ decoration: BoxDecoration(color: theme.backgroundColor ?? Colors.white),
|
|
|
child: NotificationListener(
|
|
child: NotificationListener(
|
|
|
onNotification: (ScrollNotification notification) {
|
|
onNotification: (ScrollNotification notification) {
|
|
|
if (notification.depth == 0 &&
|
|
if (notification.depth == 0 &&
|
|
@@ -276,7 +286,7 @@ class _DatePickerState extends State<_DatePickerComponent> {
|
|
|
},
|
|
},
|
|
|
child: CupertinoPicker.builder(
|
|
child: CupertinoPicker.builder(
|
|
|
key: key,
|
|
key: key,
|
|
|
- backgroundColor: theme?.backgroundColor ?? Colors.white,
|
|
|
|
|
|
|
+ backgroundColor: theme.backgroundColor ?? Colors.white,
|
|
|
scrollController: scrollController,
|
|
scrollController: scrollController,
|
|
|
itemExtent: theme.itemHeight,
|
|
itemExtent: theme.itemHeight,
|
|
|
onSelectedItemChanged: (int index) {
|
|
onSelectedItemChanged: (int index) {
|
|
@@ -293,7 +303,7 @@ class _DatePickerState extends State<_DatePickerComponent> {
|
|
|
alignment: Alignment.center,
|
|
alignment: Alignment.center,
|
|
|
child: Text(
|
|
child: Text(
|
|
|
content,
|
|
content,
|
|
|
- style: theme?.itemStyle,
|
|
|
|
|
|
|
+ style: theme.itemStyle,
|
|
|
textAlign: TextAlign.start,
|
|
textAlign: TextAlign.start,
|
|
|
),
|
|
),
|
|
|
);
|
|
);
|
|
@@ -303,11 +313,15 @@ class _DatePickerState extends State<_DatePickerComponent> {
|
|
|
|
|
|
|
|
Widget _renderItemView(DatePickerTheme theme) {
|
|
Widget _renderItemView(DatePickerTheme theme) {
|
|
|
return Container(
|
|
return Container(
|
|
|
- color: theme?.backgroundColor ?? Colors.white,
|
|
|
|
|
|
|
+ color: theme.backgroundColor ?? Colors.white,
|
|
|
child: Row(
|
|
child: Row(
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
children: <Widget>[
|
|
children: <Widget>[
|
|
|
- _renderColumnView(ValueKey(widget.pickerModel.currentLeftIndex()), theme, widget.pickerModel.leftStringAtIndex, leftScrollCtrl,
|
|
|
|
|
|
|
+ _renderColumnView(
|
|
|
|
|
+ ValueKey(widget.pickerModel.currentLeftIndex()),
|
|
|
|
|
+ theme,
|
|
|
|
|
+ widget.pickerModel.leftStringAtIndex,
|
|
|
|
|
+ leftScrollCtrl,
|
|
|
widget.pickerModel.layoutProportions()[0], (index) {
|
|
widget.pickerModel.layoutProportions()[0], (index) {
|
|
|
widget.pickerModel.setLeftIndex(index);
|
|
widget.pickerModel.setLeftIndex(index);
|
|
|
}, (index) {
|
|
}, (index) {
|
|
@@ -318,9 +332,13 @@ class _DatePickerState extends State<_DatePickerComponent> {
|
|
|
}),
|
|
}),
|
|
|
Text(
|
|
Text(
|
|
|
widget.pickerModel.leftDivider(),
|
|
widget.pickerModel.leftDivider(),
|
|
|
- style: theme?.itemStyle,
|
|
|
|
|
|
|
+ style: theme.itemStyle,
|
|
|
),
|
|
),
|
|
|
- _renderColumnView(ValueKey(widget.pickerModel.currentLeftIndex()), theme, widget.pickerModel.middleStringAtIndex, middleScrollCtrl,
|
|
|
|
|
|
|
+ _renderColumnView(
|
|
|
|
|
+ ValueKey(widget.pickerModel.currentLeftIndex()),
|
|
|
|
|
+ theme,
|
|
|
|
|
+ widget.pickerModel.middleStringAtIndex,
|
|
|
|
|
+ middleScrollCtrl,
|
|
|
widget.pickerModel.layoutProportions()[1], (index) {
|
|
widget.pickerModel.layoutProportions()[1], (index) {
|
|
|
widget.pickerModel.setMiddleIndex(index);
|
|
widget.pickerModel.setMiddleIndex(index);
|
|
|
}, (index) {
|
|
}, (index) {
|
|
@@ -331,9 +349,14 @@ class _DatePickerState extends State<_DatePickerComponent> {
|
|
|
}),
|
|
}),
|
|
|
Text(
|
|
Text(
|
|
|
widget.pickerModel.rightDivider(),
|
|
widget.pickerModel.rightDivider(),
|
|
|
- style: theme?.itemStyle,
|
|
|
|
|
|
|
+ style: theme.itemStyle,
|
|
|
),
|
|
),
|
|
|
- _renderColumnView(ValueKey(widget.pickerModel.currentMiddleIndex()), theme, widget.pickerModel.rightStringAtIndex, rightScrollCtrl,
|
|
|
|
|
|
|
+ _renderColumnView(
|
|
|
|
|
+ ValueKey(
|
|
|
|
|
+ widget.pickerModel.currentMiddleIndex() + widget.pickerModel.currentLeftIndex()),
|
|
|
|
|
+ theme,
|
|
|
|
|
+ widget.pickerModel.rightStringAtIndex,
|
|
|
|
|
+ rightScrollCtrl,
|
|
|
widget.pickerModel.layoutProportions()[2], (index) {
|
|
widget.pickerModel.layoutProportions()[2], (index) {
|
|
|
widget.pickerModel.setRightIndex(index);
|
|
widget.pickerModel.setRightIndex(index);
|
|
|
_notifyDateChanged();
|
|
_notifyDateChanged();
|
|
@@ -350,7 +373,7 @@ class _DatePickerState extends State<_DatePickerComponent> {
|
|
|
|
|
|
|
|
return Container(
|
|
return Container(
|
|
|
height: theme.titleHeight,
|
|
height: theme.titleHeight,
|
|
|
- decoration: BoxDecoration(color: theme?.backgroundColor ?? Colors.white),
|
|
|
|
|
|
|
+ decoration: BoxDecoration(color: theme.backgroundColor ?? Colors.white),
|
|
|
child: Row(
|
|
child: Row(
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
children: <Widget>[
|
|
children: <Widget>[
|
|
@@ -359,7 +382,7 @@ class _DatePickerState extends State<_DatePickerComponent> {
|
|
|
child: FlatButton(
|
|
child: FlatButton(
|
|
|
child: Text(
|
|
child: Text(
|
|
|
'$cancel',
|
|
'$cancel',
|
|
|
- style: theme?.cancelStyle,
|
|
|
|
|
|
|
+ style: theme.cancelStyle,
|
|
|
),
|
|
),
|
|
|
onPressed: () => Navigator.pop(context),
|
|
onPressed: () => Navigator.pop(context),
|
|
|
),
|
|
),
|
|
@@ -369,7 +392,7 @@ class _DatePickerState extends State<_DatePickerComponent> {
|
|
|
child: FlatButton(
|
|
child: FlatButton(
|
|
|
child: Text(
|
|
child: Text(
|
|
|
'$done',
|
|
'$done',
|
|
|
- style: theme?.doneStyle,
|
|
|
|
|
|
|
+ style: theme.doneStyle,
|
|
|
),
|
|
),
|
|
|
onPressed: () {
|
|
onPressed: () {
|
|
|
if (widget.route.onConfirm != null) {
|
|
if (widget.route.onConfirm != null) {
|
|
@@ -408,7 +431,11 @@ class _BottomPickerLayout extends SingleChildLayoutDelegate {
|
|
|
maxHeight += theme.titleHeight;
|
|
maxHeight += theme.titleHeight;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return new BoxConstraints(minWidth: constraints.maxWidth, maxWidth: constraints.maxWidth, minHeight: 0.0, maxHeight: maxHeight);
|
|
|
|
|
|
|
+ return new BoxConstraints(
|
|
|
|
|
+ minWidth: constraints.maxWidth,
|
|
|
|
|
+ maxWidth: constraints.maxWidth,
|
|
|
|
|
+ minHeight: 0.0,
|
|
|
|
|
+ maxHeight: maxHeight);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
@override
|