From 23b2037850a14f11b5a7c7ed09356b4be3688556 Mon Sep 17 00:00:00 2001 From: zh Date: Tue, 7 Mar 2023 11:12:45 +0800 Subject: [PATCH 1/9] =?UTF-8?q?[Add]=20=E8=B7=AF=E5=BE=84=E8=A7=84?= =?UTF-8?q?=E5=88=92=E6=A8=A1=E5=9D=97=20DateTimePicker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/ios/Flutter/AppFrameworkInfo.plist | 2 +- .../ios/Flutter/flutter_export_environment.sh | 14 +- example/ios/Runner.xcodeproj/project.pbxproj | 10 +- .../contents.xcworkspacedata | 2 +- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- example/ios/Runner/Info.plist | 4 + example/lib/main.dart | 296 ++++++++-------- lib/flutter_datetime_picker.dart | 325 +++++++++++------- lib/src/GreeRouteDatePickerModel.dart | 61 ++++ lib/src/datetime_picker_theme.dart | 2 +- 10 files changed, 427 insertions(+), 291 deletions(-) create mode 100644 lib/src/GreeRouteDatePickerModel.dart diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist index 9367d483..9625e105 100644 --- a/example/ios/Flutter/AppFrameworkInfo.plist +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 8.0 + 11.0 diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh index da2211a4..127d613c 100755 --- a/example/ios/Flutter/flutter_export_environment.sh +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -1,16 +1,14 @@ #!/bin/sh # This is a generated file; do not edit or check into version control. -export "FLUTTER_ROOT=/Users/liuyanbo/flutter" -export "FLUTTER_APPLICATION_PATH=/Users/liuyanbo/Documents/GitHub/flutter_datetime_picker/example" -export "FLUTTER_TARGET=/Users/liuyanbo/Documents/GitHub/flutter_datetime_picker/example/lib/main.dart" +export "FLUTTER_ROOT=/Users/zh/Library/flutter" +export "FLUTTER_APPLICATION_PATH=/Users/zh/Documents/gree/flutterProj/Fork/flutter_datetime_picker/example" +export "COCOAPODS_PARALLEL_CODE_SIGN=true" +export "FLUTTER_TARGET=/Users/zh/Documents/gree/flutterProj/Fork/flutter_datetime_picker/example/lib/main.dart" export "FLUTTER_BUILD_DIR=build" -export "SYMROOT=${SOURCE_ROOT}/../build/ios" -export "OTHER_LDFLAGS=$(inherited) -framework Flutter" -export "FLUTTER_FRAMEWORK_DIR=/Users/liuyanbo/flutter/bin/cache/artifacts/engine/ios" export "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NUMBER=1" -export "DART_DEFINES=flutter.inspector.structuredErrors%3Dtrue" +export "DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==" export "DART_OBFUSCATION=false" export "TRACK_WIDGET_CREATION=true" export "TREE_SHAKE_ICONS=false" -export "PACKAGE_CONFIG=.packages" +export "PACKAGE_CONFIG=/Users/zh/Documents/gree/flutterProj/Fork/flutter_datetime_picker/example/.dart_tool/package_config.json" diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 1c85b6d7..3d4f0cb6 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -140,7 +140,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0910; + LastUpgradeCheck = 1300; ORGANIZATIONNAME = "The Chromium Authors"; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -184,6 +184,7 @@ /* Begin PBXShellScriptBuildPhase section */ 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -198,6 +199,7 @@ }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -290,7 +292,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -337,7 +339,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 1d526a16..919434a6 100644 --- a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 1263ac84..1c19f4b8 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ UIViewControllerBasedStatusBarAppearance + CADisableMinimumFrameDurationOnPhone + + UIApplicationSupportsIndirectInputEvents + diff --git a/example/lib/main.dart b/example/lib/main.dart index 1ab0e793..241ced22 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -8,8 +8,7 @@ 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); @@ -45,36 +44,26 @@ class CustomPicker extends CommonPickerModel { @override String leftDivider() { - return "|"; + return ""; } @override String rightDivider() { - return "|"; + return ""; } @override List layoutProportions() { - return [1, 2, 1]; + return [2, 1, 1]; } @override DateTime finalTime() { return currentTime.isUtc ? DateTime.utc( - currentTime.year, - currentTime.month, - currentTime.day, - this.currentLeftIndex(), - this.currentMiddleIndex(), - this.currentRightIndex()) + 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()); + currentTime.year, currentTime.month, currentTime.day, this.currentLeftIndex(), this.currentMiddleIndex(), this.currentRightIndex()); } } @@ -102,154 +91,143 @@ class HomePage extends StatelessWidget { body: Center( child: Column( children: [ + // TextButton( + // onPressed: () { + // DatePicker.showDatePicker(context, + // showTitleActions: true, + // minTime: DateTime(2018, 3, 5), + // maxTime: DateTime(2019, 6, 7), + // theme: DatePickerTheme( + // headerColor: Colors.orange, + // backgroundColor: Colors.blue, + // itemStyle: TextStyle(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()); + // }, onConfirm: (date) { + // print('confirm $date'); + // }, currentTime: DateTime.now(), locale: LocaleType.en); + // }, + // child: Text( + // 'show date picker(custom theme &date time range)', + // style: TextStyle(color: Colors.blue), + // )), + // TextButton( + // onPressed: () { + // 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()); + // }, + // child: Text( + // 'show time picker', + // style: TextStyle(color: Colors.blue), + // )), + // TextButton( + // onPressed: () { + // 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()); + // }, + // child: Text( + // 'show 12H time picker with AM/PM', + // style: TextStyle(color: Colors.blue), + // )), TextButton( onPressed: () { - DatePicker.showDatePicker(context, - showTitleActions: true, - minTime: DateTime(2018, 3, 5), - maxTime: DateTime(2019, 6, 7), - theme: DatePickerTheme( - headerColor: Colors.orange, - backgroundColor: Colors.blue, - itemStyle: TextStyle( - 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()); - }, onConfirm: (date) { - print('confirm $date'); - }, currentTime: DateTime.now(), locale: LocaleType.en); + DatePicker.showGreeRouteDateTimePicker( + context, + showTitleActions: true, + minTime: DateTime.now(), + maxTime: DateTime.now().add(Duration(days: 1000)), + onChanged: (date) { + print('change $date in time zone ' + date.timeZoneOffset.inHours.toString()); + }, + onConfirm: (date) { + print('confirm $date'); + }, + locale: LocaleType.zh, + ); }, child: Text( - 'show date picker(custom theme &date time range)', - style: TextStyle(color: Colors.blue), - )), - TextButton( - onPressed: () { - 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()); - }, - child: Text( - 'show time picker', - style: TextStyle(color: Colors.blue), - )), - TextButton( - onPressed: () { - 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()); - }, - child: Text( - 'show 12H time picker with AM/PM', - style: TextStyle(color: Colors.blue), - )), - 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()); - }, onConfirm: (date) { - print('confirm $date'); - }, locale: LocaleType.zh); - }, - child: Text( - 'show date time picker (Chinese)', - style: TextStyle(color: Colors.blue), - )), - TextButton( - onPressed: () { - 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)); - }, - child: Text( - 'show date time picker (English-America)', - style: TextStyle(color: Colors.blue), - )), - TextButton( - onPressed: () { - 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); - }, - child: Text( - 'show date time picker (Dutch)', - style: TextStyle(color: Colors.blue), - )), - TextButton( - onPressed: () { - 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); - }, - child: Text( - 'show date time picker (Russian)', - style: TextStyle(color: Colors.blue), - )), - TextButton( - onPressed: () { - 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); - }, - child: Text( - 'show date time picker in UTC (German)', - style: TextStyle(color: Colors.blue), - )), - TextButton( - onPressed: () { - 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); - }, - child: Text( - 'show custom time picker,\nyou can custom picker model like this', + '导航 DatePicker', style: TextStyle(color: Colors.blue), )), + // TextButton( + // onPressed: () { + // 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)); + // }, + // child: Text( + // 'show date time picker (English-America)', + // style: TextStyle(color: Colors.blue), + // )), + // TextButton( + // onPressed: () { + // 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); + // }, + // child: Text( + // 'show date time picker (Dutch)', + // style: TextStyle(color: Colors.blue), + // )), + // TextButton( + // onPressed: () { + // 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); + // }, + // child: Text( + // 'show date time picker (Russian)', + // style: TextStyle(color: Colors.blue), + // )), + // TextButton( + // onPressed: () { + // 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); + // }, + // child: Text( + // 'show date time picker in UTC (German)', + // style: TextStyle(color: Colors.blue), + // )), + // TextButton( + // onPressed: () { + // 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); + // }, + // child: Text( + // 'show custom time picker,\nyou can custom picker model like this', + // style: TextStyle(color: Colors.blue), + // )), + // TextButton( + // onPressed: () { + // DatePicker.showPicker( + // context, + // pickerModel: CustomPicker(locale: LocaleType.zh), + // onChanged: (date) {}, + // onConfirm: (date) {}, + // ); + // }, + // child: Text( + // '路线规划 DatePicker', + // style: TextStyle(color: Colors.blue), + // )), ], ), ), diff --git a/lib/flutter_datetime_picker.dart b/lib/flutter_datetime_picker.dart index dba6b566..0becd723 100644 --- a/lib/flutter_datetime_picker.dart +++ b/lib/flutter_datetime_picker.dart @@ -4,6 +4,7 @@ import 'dart:async'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/painting.dart'; +import 'package:flutter_datetime_picker/src/GreeRouteDatePickerModel.dart'; import 'package:flutter_datetime_picker/src/datetime_picker_theme.dart'; import 'package:flutter_datetime_picker/src/date_model.dart'; import 'package:flutter_datetime_picker/src/i18n_model.dart'; @@ -17,10 +18,112 @@ typedef DateCancelledCallback(); typedef String? StringAtIndexCallBack(int index); class DatePicker { + // /// + // /// Display date picker bottom sheet. + // /// + // static Future showDatePicker( + // BuildContext context, { + // bool showTitleActions: true, + // DateTime? minTime, + // DateTime? maxTime, + // DateChangedCallback? onChanged, + // DateChangedCallback? onConfirm, + // DateCancelledCallback? onCancel, + // locale: LocaleType.en, + // DateTime? currentTime, + // DatePickerTheme? theme, + // }) async { + // return await Navigator.push( + // context, + // _DatePickerRoute( + // showTitleActions: showTitleActions, + // onChanged: onChanged, + // onConfirm: onConfirm, + // onCancel: onCancel, + // locale: locale, + // theme: theme, + // barrierLabel: + // MaterialLocalizations.of(context).modalBarrierDismissLabel, + // pickerModel: DatePickerModel( + // currentTime: currentTime, + // maxTime: maxTime, + // minTime: minTime, + // locale: locale, + // ), + // ), + // ); + // } + // + // /// + // /// Display time picker bottom sheet. + // /// + // static Future showTimePicker( + // BuildContext context, { + // bool showTitleActions: true, + // bool showSecondsColumn: true, + // DateChangedCallback? onChanged, + // DateChangedCallback? onConfirm, + // DateCancelledCallback? onCancel, + // locale: LocaleType.en, + // DateTime? currentTime, + // DatePickerTheme? theme, + // }) async { + // return await Navigator.push( + // context, + // _DatePickerRoute( + // showTitleActions: showTitleActions, + // onChanged: onChanged, + // onConfirm: onConfirm, + // onCancel: onCancel, + // locale: locale, + // theme: theme, + // barrierLabel: + // MaterialLocalizations.of(context).modalBarrierDismissLabel, + // pickerModel: TimePickerModel( + // currentTime: currentTime, + // locale: locale, + // showSecondsColumn: showSecondsColumn, + // ), + // ), + // ); + // } + // + // /// + // /// Display time picker bottom sheet with AM/PM. + // /// + // static Future showTime12hPicker( + // BuildContext context, { + // bool showTitleActions: true, + // DateChangedCallback? onChanged, + // DateChangedCallback? onConfirm, + // DateCancelledCallback? onCancel, + // locale: LocaleType.en, + // DateTime? currentTime, + // DatePickerTheme? theme, + // }) async { + // return await Navigator.push( + // context, + // _DatePickerRoute( + // showTitleActions: showTitleActions, + // onChanged: onChanged, + // onConfirm: onConfirm, + // onCancel: onCancel, + // locale: locale, + // theme: theme, + // barrierLabel: + // MaterialLocalizations.of(context).modalBarrierDismissLabel, + // pickerModel: Time12hPickerModel( + // currentTime: currentTime, + // locale: locale, + // ), + // ), + // ); + // } + /// - /// Display date picker bottom sheet. + /// Display date&time picker bottom sheet. /// - static Future showDatePicker( + static Future showDateTimePicker( BuildContext context, { bool showTitleActions: true, DateTime? minTime, @@ -43,97 +146,28 @@ class DatePicker { theme: theme, barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel, - pickerModel: DatePickerModel( + pickerModel: DateTimePickerModel( currentTime: currentTime, - maxTime: maxTime, minTime: minTime, + maxTime: maxTime, locale: locale, ), ), ); } - /// - /// Display time picker bottom sheet. - /// - static Future showTimePicker( - BuildContext context, { - bool showTitleActions: true, - bool showSecondsColumn: true, - DateChangedCallback? onChanged, - DateChangedCallback? onConfirm, - DateCancelledCallback? onCancel, - locale: LocaleType.en, - DateTime? currentTime, - DatePickerTheme? theme, - }) async { - return await Navigator.push( - context, - _DatePickerRoute( - showTitleActions: showTitleActions, - onChanged: onChanged, - onConfirm: onConfirm, - onCancel: onCancel, - locale: locale, - theme: theme, - barrierLabel: - MaterialLocalizations.of(context).modalBarrierDismissLabel, - pickerModel: TimePickerModel( - currentTime: currentTime, - locale: locale, - showSecondsColumn: showSecondsColumn, - ), - ), - ); - } - - /// - /// Display time picker bottom sheet with AM/PM. - /// - static Future showTime12hPicker( - BuildContext context, { - bool showTitleActions: true, - DateChangedCallback? onChanged, - DateChangedCallback? onConfirm, - DateCancelledCallback? onCancel, - locale: LocaleType.en, - DateTime? currentTime, - DatePickerTheme? theme, - }) async { - return await Navigator.push( - context, - _DatePickerRoute( - showTitleActions: showTitleActions, - onChanged: onChanged, - onConfirm: onConfirm, - onCancel: onCancel, - locale: locale, - theme: theme, - barrierLabel: - MaterialLocalizations.of(context).modalBarrierDismissLabel, - pickerModel: Time12hPickerModel( - currentTime: currentTime, - locale: locale, - ), - ), - ); - } - - /// - /// Display date&time picker bottom sheet. - /// - static Future showDateTimePicker( - BuildContext context, { - bool showTitleActions: true, - DateTime? minTime, - DateTime? maxTime, - DateChangedCallback? onChanged, - DateChangedCallback? onConfirm, - DateCancelledCallback? onCancel, - locale: LocaleType.en, - DateTime? currentTime, - DatePickerTheme? theme, - }) async { + static Future showGreeRouteDateTimePicker( + BuildContext context, { + bool showTitleActions: true, + DateTime? minTime, + DateTime? maxTime, + DateChangedCallback? onChanged, + DateChangedCallback? onConfirm, + DateCancelledCallback? onCancel, + locale: LocaleType.en, + DateTime? currentTime, + DatePickerTheme? theme, + }) async { return await Navigator.push( context, _DatePickerRoute( @@ -144,8 +178,8 @@ class DatePicker { locale: locale, theme: theme, barrierLabel: - MaterialLocalizations.of(context).modalBarrierDismissLabel, - pickerModel: DateTimePickerModel( + MaterialLocalizations.of(context).modalBarrierDismissLabel, + pickerModel: GreeRouteDatePickerModel( currentTime: currentTime, minTime: minTime, maxTime: maxTime, @@ -155,34 +189,73 @@ class DatePicker { ); } - /// - /// Display date picker bottom sheet witch custom picker model. - /// - static Future showPicker( - BuildContext context, { - bool showTitleActions: true, - DateChangedCallback? onChanged, - DateChangedCallback? onConfirm, - DateCancelledCallback? onCancel, - locale: LocaleType.en, - BasePickerModel? pickerModel, - DatePickerTheme? theme, - }) async { - return await Navigator.push( - context, - _DatePickerRoute( - showTitleActions: showTitleActions, - onChanged: onChanged, - onConfirm: onConfirm, - onCancel: onCancel, - locale: locale, - theme: theme, - barrierLabel: - MaterialLocalizations.of(context).modalBarrierDismissLabel, - pickerModel: pickerModel, - ), - ); - } + + // + // + // /// + // /// 格力路径规划时间选择器 + // /// + // static Future showGreeRouteDatePicker( + // BuildContext context, { + // bool showTitleActions: true, + // DateTime? minTime, + // DateTime? maxTime, + // DateChangedCallback? onChanged, + // DateChangedCallback? onConfirm, + // DateCancelledCallback? onCancel, + // locale: LocaleType.en, + // DateTime? currentTime, + // DatePickerTheme? theme, + // }) async { + // return await Navigator.push( + // context, + // _DatePickerRoute( + // showTitleActions: showTitleActions, + // onChanged: onChanged, + // onConfirm: onConfirm, + // onCancel: onCancel, + // locale: locale, + // theme: theme, + // barrierLabel: + // MaterialLocalizations.of(context).modalBarrierDismissLabel, + // pickerModel: DateTimePickerModel( + // currentTime: currentTime, + // minTime: minTime, + // maxTime: maxTime, + // locale: locale, + // ), + // ), + // ); + // } + // + // /// + // /// Display date picker bottom sheet witch custom picker model. + // /// + // static Future showPicker( + // BuildContext context, { + // bool showTitleActions: true, + // DateChangedCallback? onChanged, + // DateChangedCallback? onConfirm, + // DateCancelledCallback? onCancel, + // locale: LocaleType.en, + // BasePickerModel? pickerModel, + // DatePickerTheme? theme, + // }) async { + // return await Navigator.push( + // context, + // _DatePickerRoute( + // showTitleActions: showTitleActions, + // onChanged: onChanged, + // onConfirm: onConfirm, + // onCancel: onCancel, + // locale: locale, + // theme: theme, + // barrierLabel: + // MaterialLocalizations.of(context).modalBarrierDismissLabel, + // pickerModel: pickerModel, + // ), + // ); + // } } class _DatePickerRoute extends PopupRoute { @@ -339,6 +412,26 @@ class _DatePickerState extends State<_DatePickerComponent> { return itemView; } + /// 上下分割线 + Widget _buildMagnifierScreen(double itemExtent) { + final Color resolvedBorderColor = CupertinoDynamicColor.resolve(Color(0xFFEBEDF5), context); + return IgnorePointer( + child: Center( + child: Container( + decoration: BoxDecoration( + border: Border( + top: BorderSide(width: 0.0, color: resolvedBorderColor), + bottom: BorderSide(width: 0.0, color: resolvedBorderColor), + ), + ), + constraints: BoxConstraints.expand( + height: itemExtent, + ), + ), + ), + ); + } + Widget _renderColumnView( ValueKey key, DatePickerTheme theme, @@ -351,7 +444,6 @@ class _DatePickerState extends State<_DatePickerComponent> { return Expanded( flex: layoutProportion, child: Container( - padding: EdgeInsets.all(8.0), height: theme.containerHeight, decoration: BoxDecoration(color: theme.backgroundColor), child: NotificationListener( @@ -369,6 +461,7 @@ class _DatePickerState extends State<_DatePickerComponent> { child: CupertinoPicker.builder( key: key, backgroundColor: theme.backgroundColor, + selectionOverlay: _buildMagnifierScreen(theme.itemHeight), scrollController: scrollController as FixedExtentScrollController, itemExtent: theme.itemHeight, onSelectedItemChanged: (int index) { diff --git a/lib/src/GreeRouteDatePickerModel.dart b/lib/src/GreeRouteDatePickerModel.dart new file mode 100644 index 00000000..66d6394e --- /dev/null +++ b/lib/src/GreeRouteDatePickerModel.dart @@ -0,0 +1,61 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; +import 'package:flutter_datetime_picker/src/date_format.dart'; + +class GreeRouteDatePickerModel extends DateTimePickerModel { + + GreeRouteDatePickerModel({ + DateTime? currentTime, + DateTime? maxTime, + DateTime? minTime, + LocaleType? locale, + }) : super( + currentTime: currentTime, + maxTime: maxTime, + minTime: minTime, + locale: locale, + ); + + @override + String? middleStringAtIndex(int index) { + String? hour = super.middleStringAtIndex(index); + return hour == null ? null : '$hour 时'; + } + + @override + String? rightStringAtIndex(int index) { + String? min = super.rightStringAtIndex(index); + return min == null ? null : '$min 分'; + } + + @override + String? leftStringAtIndex(int index) { + DateTime time = currentTime.add(Duration(days: index)); + if (minTime != null && + time.isBefore(minTime!) && + !isAtSameDay(minTime!, time)) { + return null; + } else if (maxTime != null && + time.isAfter(maxTime!) && + !isAtSameDay(maxTime, time)) { + return null; + } + return '${time.year}年${time.month}月${time.day}日'; + } + + @override + List layoutProportions() { + return [2, 1, 1]; + } + + @override + String leftDivider() { + return ''; + } + + @override + String rightDivider() { + return ''; + } + +} diff --git a/lib/src/datetime_picker_theme.dart b/lib/src/datetime_picker_theme.dart index e3f616f4..133c964b 100644 --- a/lib/src/datetime_picker_theme.dart +++ b/lib/src/datetime_picker_theme.dart @@ -17,7 +17,7 @@ class DatePickerTheme with DiagnosticableTreeMixin { const DatePickerTheme({ this.cancelStyle = const TextStyle(color: Colors.black54, fontSize: 16), this.doneStyle = const TextStyle(color: Colors.blue, fontSize: 16), - this.itemStyle = const TextStyle(color: Color(0xFF000046), fontSize: 18), + this.itemStyle = const TextStyle(color: Color(0xFF333333), fontSize: 18), this.backgroundColor = Colors.white, this.headerColor, this.containerHeight = 210.0, From 76949dd43c25cb129a76d492abaac5b36a4e6ee3 Mon Sep 17 00:00:00 2001 From: zh Date: Tue, 7 Mar 2023 14:02:58 +0800 Subject: [PATCH 2/9] [Mod] headerView add title --- example/lib/main.dart | 1 + lib/flutter_datetime_picker.dart | 292 +++++++++++++---------------- lib/src/datetime_picker_theme.dart | 19 +- 3 files changed, 147 insertions(+), 165 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 241ced22..b12f894b 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -142,6 +142,7 @@ class HomePage extends StatelessWidget { showTitleActions: true, minTime: DateTime.now(), maxTime: DateTime.now().add(Duration(days: 1000)), + theme: DatePickerTheme(title: '开始时间'), onChanged: (date) { print('change $date in time zone ' + date.timeZoneOffset.inHours.toString()); }, diff --git a/lib/flutter_datetime_picker.dart b/lib/flutter_datetime_picker.dart index 0becd723..772debee 100644 --- a/lib/flutter_datetime_picker.dart +++ b/lib/flutter_datetime_picker.dart @@ -144,8 +144,7 @@ class DatePicker { onCancel: onCancel, locale: locale, theme: theme, - barrierLabel: - MaterialLocalizations.of(context).modalBarrierDismissLabel, + barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel, pickerModel: DateTimePickerModel( currentTime: currentTime, minTime: minTime, @@ -157,17 +156,17 @@ class DatePicker { } static Future showGreeRouteDateTimePicker( - BuildContext context, { - bool showTitleActions: true, - DateTime? minTime, - DateTime? maxTime, - DateChangedCallback? onChanged, - DateChangedCallback? onConfirm, - DateCancelledCallback? onCancel, - locale: LocaleType.en, - DateTime? currentTime, - DatePickerTheme? theme, - }) async { + BuildContext context, { + bool showTitleActions: true, + DateTime? minTime, + DateTime? maxTime, + DateChangedCallback? onChanged, + DateChangedCallback? onConfirm, + DateCancelledCallback? onCancel, + locale: LocaleType.en, + DateTime? currentTime, + DatePickerTheme? theme, + }) async { return await Navigator.push( context, _DatePickerRoute( @@ -177,8 +176,7 @@ class DatePicker { onCancel: onCancel, locale: locale, theme: theme, - barrierLabel: - MaterialLocalizations.of(context).modalBarrierDismissLabel, + barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel, pickerModel: GreeRouteDatePickerModel( currentTime: currentTime, minTime: minTime, @@ -189,73 +187,72 @@ class DatePicker { ); } - - // - // - // /// - // /// 格力路径规划时间选择器 - // /// - // static Future showGreeRouteDatePicker( - // BuildContext context, { - // bool showTitleActions: true, - // DateTime? minTime, - // DateTime? maxTime, - // DateChangedCallback? onChanged, - // DateChangedCallback? onConfirm, - // DateCancelledCallback? onCancel, - // locale: LocaleType.en, - // DateTime? currentTime, - // DatePickerTheme? theme, - // }) async { - // return await Navigator.push( - // context, - // _DatePickerRoute( - // showTitleActions: showTitleActions, - // onChanged: onChanged, - // onConfirm: onConfirm, - // onCancel: onCancel, - // locale: locale, - // theme: theme, - // barrierLabel: - // MaterialLocalizations.of(context).modalBarrierDismissLabel, - // pickerModel: DateTimePickerModel( - // currentTime: currentTime, - // minTime: minTime, - // maxTime: maxTime, - // locale: locale, - // ), - // ), - // ); - // } - // - // /// - // /// Display date picker bottom sheet witch custom picker model. - // /// - // static Future showPicker( - // BuildContext context, { - // bool showTitleActions: true, - // DateChangedCallback? onChanged, - // DateChangedCallback? onConfirm, - // DateCancelledCallback? onCancel, - // locale: LocaleType.en, - // BasePickerModel? pickerModel, - // DatePickerTheme? theme, - // }) async { - // return await Navigator.push( - // context, - // _DatePickerRoute( - // showTitleActions: showTitleActions, - // onChanged: onChanged, - // onConfirm: onConfirm, - // onCancel: onCancel, - // locale: locale, - // theme: theme, - // barrierLabel: - // MaterialLocalizations.of(context).modalBarrierDismissLabel, - // pickerModel: pickerModel, - // ), - // ); - // } +// +// +// /// +// /// 格力路径规划时间选择器 +// /// +// static Future showGreeRouteDatePicker( +// BuildContext context, { +// bool showTitleActions: true, +// DateTime? minTime, +// DateTime? maxTime, +// DateChangedCallback? onChanged, +// DateChangedCallback? onConfirm, +// DateCancelledCallback? onCancel, +// locale: LocaleType.en, +// DateTime? currentTime, +// DatePickerTheme? theme, +// }) async { +// return await Navigator.push( +// context, +// _DatePickerRoute( +// showTitleActions: showTitleActions, +// onChanged: onChanged, +// onConfirm: onConfirm, +// onCancel: onCancel, +// locale: locale, +// theme: theme, +// barrierLabel: +// MaterialLocalizations.of(context).modalBarrierDismissLabel, +// pickerModel: DateTimePickerModel( +// currentTime: currentTime, +// minTime: minTime, +// maxTime: maxTime, +// locale: locale, +// ), +// ), +// ); +// } +// +// /// +// /// Display date picker bottom sheet witch custom picker model. +// /// +// static Future showPicker( +// BuildContext context, { +// bool showTitleActions: true, +// DateChangedCallback? onChanged, +// DateChangedCallback? onConfirm, +// DateCancelledCallback? onCancel, +// locale: LocaleType.en, +// BasePickerModel? pickerModel, +// DatePickerTheme? theme, +// }) async { +// return await Navigator.push( +// context, +// _DatePickerRoute( +// showTitleActions: showTitleActions, +// onChanged: onChanged, +// onConfirm: onConfirm, +// onCancel: onCancel, +// locale: locale, +// theme: theme, +// barrierLabel: +// MaterialLocalizations.of(context).modalBarrierDismissLabel, +// pickerModel: pickerModel, +// ), +// ); +// } } class _DatePickerRoute extends PopupRoute { @@ -298,14 +295,12 @@ class _DatePickerRoute extends PopupRoute { @override AnimationController createAnimationController() { assert(_animationController == null); - _animationController = - BottomSheet.createAnimationController(navigator!.overlay!); + _animationController = BottomSheet.createAnimationController(navigator!.overlay!); return _animationController!; } @override - Widget buildPage(BuildContext context, Animation animation, - Animation secondaryAnimation) { + Widget buildPage(BuildContext context, Animation animation, Animation secondaryAnimation) { Widget bottomSheet = MediaQuery.removePadding( context: context, removeTop: true, @@ -344,9 +339,7 @@ class _DatePickerComponent extends StatefulWidget { } class _DatePickerState extends State<_DatePickerComponent> { - late FixedExtentScrollController leftScrollCtrl, - middleScrollCtrl, - rightScrollCtrl; + late FixedExtentScrollController leftScrollCtrl, middleScrollCtrl, rightScrollCtrl; @override void initState() { @@ -356,12 +349,9 @@ class _DatePickerState extends State<_DatePickerComponent> { void refreshScrollOffset() { // print('refreshScrollOffset ${widget.pickerModel.currentRightIndex()}'); - leftScrollCtrl = FixedExtentScrollController( - initialItem: widget.pickerModel.currentLeftIndex()); - middleScrollCtrl = FixedExtentScrollController( - initialItem: widget.pickerModel.currentMiddleIndex()); - rightScrollCtrl = FixedExtentScrollController( - initialItem: widget.pickerModel.currentRightIndex()); + leftScrollCtrl = FixedExtentScrollController(initialItem: widget.pickerModel.currentLeftIndex()); + middleScrollCtrl = FixedExtentScrollController(initialItem: widget.pickerModel.currentMiddleIndex()); + rightScrollCtrl = FixedExtentScrollController(initialItem: widget.pickerModel.currentRightIndex()); } @override @@ -382,7 +372,7 @@ class _DatePickerState extends State<_DatePickerComponent> { ), child: GestureDetector( child: Material( - color: theme.backgroundColor, + color: Colors.transparent, child: _renderPickerView(theme), ), ), @@ -406,6 +396,9 @@ class _DatePickerState extends State<_DatePickerComponent> { children: [ _renderTitleActionsView(theme), itemView, + Expanded( + child: Container(color: theme.backgroundColor), + ) ], ); } @@ -448,11 +441,8 @@ class _DatePickerState extends State<_DatePickerComponent> { decoration: BoxDecoration(color: theme.backgroundColor), child: NotificationListener( onNotification: (ScrollNotification notification) { - if (notification.depth == 0 && - notification is ScrollEndNotification && - notification.metrics is FixedExtentMetrics) { - final FixedExtentMetrics metrics = - notification.metrics as FixedExtentMetrics; + if (notification.depth == 0 && notification is ScrollEndNotification && notification.metrics is FixedExtentMetrics) { + final FixedExtentMetrics metrics = notification.metrics as FixedExtentMetrics; final int currentItemIndex = metrics.itemIndex; selectedChangedWhenScrollEnd(currentItemIndex); } @@ -499,11 +489,7 @@ class _DatePickerState extends State<_DatePickerComponent> { children: [ Container( child: widget.pickerModel.layoutProportions()[0] > 0 - ? _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.setLeftIndex(index); }, (index) { @@ -520,12 +506,8 @@ class _DatePickerState extends State<_DatePickerComponent> { ), Container( child: widget.pickerModel.layoutProportions()[1] > 0 - ? _renderColumnView( - ValueKey(widget.pickerModel.currentLeftIndex()), - theme, - widget.pickerModel.middleStringAtIndex, - middleScrollCtrl, - widget.pickerModel.layoutProportions()[1], (index) { + ? _renderColumnView(ValueKey(widget.pickerModel.currentLeftIndex()), theme, widget.pickerModel.middleStringAtIndex, + middleScrollCtrl, widget.pickerModel.layoutProportions()[1], (index) { widget.pickerModel.setMiddleIndex(index); }, (index) { setState(() { @@ -541,13 +523,8 @@ class _DatePickerState extends State<_DatePickerComponent> { ), Container( child: widget.pickerModel.layoutProportions()[2] > 0 - ? _renderColumnView( - ValueKey(widget.pickerModel.currentMiddleIndex() * 100 + - widget.pickerModel.currentLeftIndex()), - theme, - widget.pickerModel.rightStringAtIndex, - rightScrollCtrl, - widget.pickerModel.layoutProportions()[2], (index) { + ? _renderColumnView(ValueKey(widget.pickerModel.currentMiddleIndex() * 100 + widget.pickerModel.currentLeftIndex()), theme, + widget.pickerModel.rightStringAtIndex, rightScrollCtrl, widget.pickerModel.layoutProportions()[2], (index) { widget.pickerModel.setRightIndex(index); }, (index) { setState(() { @@ -565,51 +542,51 @@ class _DatePickerState extends State<_DatePickerComponent> { // Title View Widget _renderTitleActionsView(DatePickerTheme theme) { - final done = _localeDone(); final cancel = _localeCancel(); - return Container( height: theme.titleHeight, decoration: BoxDecoration( - color: theme.headerColor ?? theme.backgroundColor, + color: theme.headerColor, + borderRadius: BorderRadius.only(topLeft: Radius.circular(12), topRight: Radius.circular(12)), ), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Container( - height: theme.titleHeight, - child: CupertinoButton( - pressedOpacity: 0.3, - padding: EdgeInsetsDirectional.only(start: 16, top: 0), - child: Text( - '$cancel', - style: theme.cancelStyle, + child: Column( + children: [ + Row( + // mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: Container( + margin: const EdgeInsets.only(left: 66), + alignment: Alignment.center, + height: theme.titleHeight - 1, + child: Text( + theme.title, + style: theme.titleStyle, + ), + ), ), - onPressed: () { - Navigator.pop(context); - if (widget.route.onCancel != null) { - widget.route.onCancel!(); - } - }, - ), - ), - Container( - height: theme.titleHeight, - child: CupertinoButton( - pressedOpacity: 0.3, - padding: EdgeInsetsDirectional.only(end: 16, top: 0), - child: Text( - '$done', - style: theme.doneStyle, + Container( + margin: const EdgeInsets.only(right: 16), + alignment: Alignment.centerRight, + height: theme.titleHeight - 1, + child: CupertinoButton( + pressedOpacity: 0.3, + padding: EdgeInsetsDirectional.only(start: 16, top: 0), + child: Text( + '$cancel', + style: theme.cancelStyle, + ), + onPressed: () { + Navigator.pop(context); + if (widget.route.onCancel != null) { + widget.route.onCancel!(); + } + }, + ), ), - onPressed: () { - Navigator.pop(context, widget.pickerModel.finalTime()); - if (widget.route.onConfirm != null) { - widget.route.onConfirm!(widget.pickerModel.finalTime()!); - } - }, - ), + ], ), + Container(height: 1, color: Color(0xFFEBEDF5)), ], ), ); @@ -620,7 +597,8 @@ class _DatePickerState extends State<_DatePickerComponent> { } String _localeCancel() { - return i18nObjInLocale(widget.locale)['cancel'] as String; + return '关闭'; + // return i18nObjInLocale(widget.locale)['cancel'] as String; } } diff --git a/lib/src/datetime_picker_theme.dart b/lib/src/datetime_picker_theme.dart index 133c964b..0e84a7e0 100644 --- a/lib/src/datetime_picker_theme.dart +++ b/lib/src/datetime_picker_theme.dart @@ -7,21 +7,24 @@ class DatePickerTheme with DiagnosticableTreeMixin { final TextStyle cancelStyle; final TextStyle doneStyle; final TextStyle itemStyle; + final TextStyle titleStyle; + final String title; final Color backgroundColor; - final Color? headerColor; - + final Color headerColor; final double containerHeight; final double titleHeight; final double itemHeight; const DatePickerTheme({ - this.cancelStyle = const TextStyle(color: Colors.black54, fontSize: 16), - this.doneStyle = const TextStyle(color: Colors.blue, fontSize: 16), + this.cancelStyle = const TextStyle(color: Color(0xFF409EFF), fontSize: 16), + this.doneStyle = const TextStyle(color: Colors.black, fontSize: 16), this.itemStyle = const TextStyle(color: Color(0xFF333333), fontSize: 18), + this.titleStyle = const TextStyle(color: Color(0xFF333333), fontSize: 18, fontWeight: FontWeight.w600), + this.title = '', this.backgroundColor = Colors.white, - this.headerColor, - this.containerHeight = 210.0, - this.titleHeight = 44.0, - this.itemHeight = 36.0, + this.headerColor = Colors.white, + this.containerHeight = 330.0, + this.titleHeight = 74.0, + this.itemHeight = 48.0, }); } From 06ea51e72417934ed53d93281b803bc243d33642 Mon Sep 17 00:00:00 2001 From: zh Date: Tue, 7 Mar 2023 14:06:24 +0800 Subject: [PATCH 3/9] [Mod] clear code --- lib/flutter_datetime_picker.dart | 207 +------------------------------ 1 file changed, 4 insertions(+), 203 deletions(-) diff --git a/lib/flutter_datetime_picker.dart b/lib/flutter_datetime_picker.dart index 772debee..d19e4f27 100644 --- a/lib/flutter_datetime_picker.dart +++ b/lib/flutter_datetime_picker.dart @@ -18,143 +18,11 @@ typedef DateCancelledCallback(); typedef String? StringAtIndexCallBack(int index); class DatePicker { - // /// - // /// Display date picker bottom sheet. - // /// - // static Future showDatePicker( - // BuildContext context, { - // bool showTitleActions: true, - // DateTime? minTime, - // DateTime? maxTime, - // DateChangedCallback? onChanged, - // DateChangedCallback? onConfirm, - // DateCancelledCallback? onCancel, - // locale: LocaleType.en, - // DateTime? currentTime, - // DatePickerTheme? theme, - // }) async { - // return await Navigator.push( - // context, - // _DatePickerRoute( - // showTitleActions: showTitleActions, - // onChanged: onChanged, - // onConfirm: onConfirm, - // onCancel: onCancel, - // locale: locale, - // theme: theme, - // barrierLabel: - // MaterialLocalizations.of(context).modalBarrierDismissLabel, - // pickerModel: DatePickerModel( - // currentTime: currentTime, - // maxTime: maxTime, - // minTime: minTime, - // locale: locale, - // ), - // ), - // ); - // } - // - // /// - // /// Display time picker bottom sheet. - // /// - // static Future showTimePicker( - // BuildContext context, { - // bool showTitleActions: true, - // bool showSecondsColumn: true, - // DateChangedCallback? onChanged, - // DateChangedCallback? onConfirm, - // DateCancelledCallback? onCancel, - // locale: LocaleType.en, - // DateTime? currentTime, - // DatePickerTheme? theme, - // }) async { - // return await Navigator.push( - // context, - // _DatePickerRoute( - // showTitleActions: showTitleActions, - // onChanged: onChanged, - // onConfirm: onConfirm, - // onCancel: onCancel, - // locale: locale, - // theme: theme, - // barrierLabel: - // MaterialLocalizations.of(context).modalBarrierDismissLabel, - // pickerModel: TimePickerModel( - // currentTime: currentTime, - // locale: locale, - // showSecondsColumn: showSecondsColumn, - // ), - // ), - // ); - // } - // - // /// - // /// Display time picker bottom sheet with AM/PM. - // /// - // static Future showTime12hPicker( - // BuildContext context, { - // bool showTitleActions: true, - // DateChangedCallback? onChanged, - // DateChangedCallback? onConfirm, - // DateCancelledCallback? onCancel, - // locale: LocaleType.en, - // DateTime? currentTime, - // DatePickerTheme? theme, - // }) async { - // return await Navigator.push( - // context, - // _DatePickerRoute( - // showTitleActions: showTitleActions, - // onChanged: onChanged, - // onConfirm: onConfirm, - // onCancel: onCancel, - // locale: locale, - // theme: theme, - // barrierLabel: - // MaterialLocalizations.of(context).modalBarrierDismissLabel, - // pickerModel: Time12hPickerModel( - // currentTime: currentTime, - // locale: locale, - // ), - // ), - // ); - // } - - /// - /// Display date&time picker bottom sheet. - /// - static Future showDateTimePicker( - BuildContext context, { - bool showTitleActions: true, - DateTime? minTime, - DateTime? maxTime, - DateChangedCallback? onChanged, - DateChangedCallback? onConfirm, - DateCancelledCallback? onCancel, - locale: LocaleType.en, - DateTime? currentTime, - DatePickerTheme? theme, - }) async { - return await Navigator.push( - context, - _DatePickerRoute( - showTitleActions: showTitleActions, - onChanged: onChanged, - onConfirm: onConfirm, - onCancel: onCancel, - locale: locale, - theme: theme, - barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel, - pickerModel: DateTimePickerModel( - currentTime: currentTime, - minTime: minTime, - maxTime: maxTime, - locale: locale, - ), - ), - ); - } + /* + * + * 路径规划时间日期选择器 + * */ static Future showGreeRouteDateTimePicker( BuildContext context, { bool showTitleActions: true, @@ -186,73 +54,6 @@ class DatePicker { ), ); } - -// -// -// /// -// /// 格力路径规划时间选择器 -// /// -// static Future showGreeRouteDatePicker( -// BuildContext context, { -// bool showTitleActions: true, -// DateTime? minTime, -// DateTime? maxTime, -// DateChangedCallback? onChanged, -// DateChangedCallback? onConfirm, -// DateCancelledCallback? onCancel, -// locale: LocaleType.en, -// DateTime? currentTime, -// DatePickerTheme? theme, -// }) async { -// return await Navigator.push( -// context, -// _DatePickerRoute( -// showTitleActions: showTitleActions, -// onChanged: onChanged, -// onConfirm: onConfirm, -// onCancel: onCancel, -// locale: locale, -// theme: theme, -// barrierLabel: -// MaterialLocalizations.of(context).modalBarrierDismissLabel, -// pickerModel: DateTimePickerModel( -// currentTime: currentTime, -// minTime: minTime, -// maxTime: maxTime, -// locale: locale, -// ), -// ), -// ); -// } -// -// /// -// /// Display date picker bottom sheet witch custom picker model. -// /// -// static Future showPicker( -// BuildContext context, { -// bool showTitleActions: true, -// DateChangedCallback? onChanged, -// DateChangedCallback? onConfirm, -// DateCancelledCallback? onCancel, -// locale: LocaleType.en, -// BasePickerModel? pickerModel, -// DatePickerTheme? theme, -// }) async { -// return await Navigator.push( -// context, -// _DatePickerRoute( -// showTitleActions: showTitleActions, -// onChanged: onChanged, -// onConfirm: onConfirm, -// onCancel: onCancel, -// locale: locale, -// theme: theme, -// barrierLabel: -// MaterialLocalizations.of(context).modalBarrierDismissLabel, -// pickerModel: pickerModel, -// ), -// ); -// } } class _DatePickerRoute extends PopupRoute { From c3dc0e5dc6f0e3a196e20bf470c922d64de91b0d Mon Sep 17 00:00:00 2001 From: zh Date: Wed, 8 Mar 2023 16:28:27 +0800 Subject: [PATCH 4/9] =?UTF-8?q?[Mod]=20=E8=A7=A3=E5=86=B3=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E6=9C=80=E5=B0=8F=E6=97=A5=E6=9C=9F=E4=B8=BA=E5=90=8C?= =?UTF-8?q?=E4=B8=80=E5=A4=A9=E6=97=B6=E7=9A=84=E6=98=BE=E7=A4=BA=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/lib/main.dart | 4 +-- lib/base_popup_route.dart | 37 +++++++++++++++++++++++++++ lib/src/GreeRouteDatePickerModel.dart | 34 ++++++++++++++++-------- lib/src/date_model.dart | 2 ++ 4 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 lib/base_popup_route.dart diff --git a/example/lib/main.dart b/example/lib/main.dart index b12f894b..0928e2d5 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -140,8 +140,8 @@ class HomePage extends StatelessWidget { DatePicker.showGreeRouteDateTimePicker( context, showTitleActions: true, - minTime: DateTime.now(), - maxTime: DateTime.now().add(Duration(days: 1000)), + minTime: DateTime(2023, 3, 8, 16, 28), + maxTime: DateTime(2023, 3, 9, 2, 2), theme: DatePickerTheme(title: '开始时间'), onChanged: (date) { print('change $date in time zone ' + date.timeZoneOffset.inHours.toString()); diff --git a/lib/base_popup_route.dart b/lib/base_popup_route.dart new file mode 100644 index 00000000..712dc9b4 --- /dev/null +++ b/lib/base_popup_route.dart @@ -0,0 +1,37 @@ +import 'package:flutter/material.dart'; + +class TestInfo { + String? name; +} + +class GMDialog { + static Future showDialog(BuildContext context) async { + return await Navigator.push(context, GMBasePopupRoute()); + } +} + +class GMBasePopupRoute extends PopupRoute { + @override + Color? get barrierColor => Colors.black54; + + @override + bool get barrierDismissible => true; + + @override + String? barrierLabel; + + @override + Widget buildPage(BuildContext context, Animation animation, Animation secondaryAnimation) { + Widget bottom = MediaQuery.removePadding( + context: context, + removeTop: true, + child: Container( + color: Colors.red, + height: 300, + )); + return InheritedTheme.captureAll(context, bottom); + } + + @override + Duration get transitionDuration => const Duration(milliseconds: 250); +} diff --git a/lib/src/GreeRouteDatePickerModel.dart b/lib/src/GreeRouteDatePickerModel.dart index 66d6394e..6d1c6154 100644 --- a/lib/src/GreeRouteDatePickerModel.dart +++ b/lib/src/GreeRouteDatePickerModel.dart @@ -3,7 +3,6 @@ import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; import 'package:flutter_datetime_picker/src/date_format.dart'; class GreeRouteDatePickerModel extends DateTimePickerModel { - GreeRouteDatePickerModel({ DateTime? currentTime, DateTime? maxTime, @@ -19,25 +18,41 @@ class GreeRouteDatePickerModel extends DateTimePickerModel { @override String? middleStringAtIndex(int index) { String? hour = super.middleStringAtIndex(index); + /// 修复时间为同一天的显示bug + if (isAtSameDay(maxTime, minTime)) { + // hour + if (int.parse(hour ?? '0') <= (maxTime?.hour ?? 0) && int.parse(hour ?? '0') >= (minTime?.hour ?? 0)) { + return hour == null ? null : '$hour 时'; + } + return null; + } return hour == null ? null : '$hour 时'; } @override String? rightStringAtIndex(int index) { - String? min = super.rightStringAtIndex(index); - return min == null ? null : '$min 分'; + String? minute = super.rightStringAtIndex(index); + int hour = finalTime().hour; + + /// 修复时间为同一天的显示bug + if (isAtSameDay(maxTime, minTime)) { + if (hour < (maxTime?.hour ?? 0)) { + return minute == null ? null : '$minute 分'; + } + if (int.parse(minute ?? '0') <= (maxTime?.minute ?? 0) && int.parse(minute ?? '0') >= (minTime?.minute ?? 0)) { + return minute == null ? null : '$minute 分'; + } + return null; + } + return minute == null ? null : '$minute 分'; } @override 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 '${time.year}年${time.month}月${time.day}日'; @@ -57,5 +72,4 @@ class GreeRouteDatePickerModel extends DateTimePickerModel { String rightDivider() { return ''; } - } diff --git a/lib/src/date_model.dart b/lib/src/date_model.dart index 0e899870..7bf98f1d 100644 --- a/lib/src/date_model.dart +++ b/lib/src/date_model.dart @@ -626,6 +626,8 @@ class DateTimePickerModel extends CommonPickerModel { 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); From 3cadb64a42c21a71748e198af05dd9c51de69222 Mon Sep 17 00:00:00 2001 From: zh Date: Wed, 8 Mar 2023 16:47:31 +0800 Subject: [PATCH 5/9] [Mod] rename --- lib/flutter_datetime_picker.dart | 2 +- ...teDatePickerModel.dart => gree_route_date_picker_model.dart} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename lib/src/{GreeRouteDatePickerModel.dart => gree_route_date_picker_model.dart} (100%) diff --git a/lib/flutter_datetime_picker.dart b/lib/flutter_datetime_picker.dart index d19e4f27..0cd1ee47 100644 --- a/lib/flutter_datetime_picker.dart +++ b/lib/flutter_datetime_picker.dart @@ -4,7 +4,7 @@ import 'dart:async'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/painting.dart'; -import 'package:flutter_datetime_picker/src/GreeRouteDatePickerModel.dart'; +import 'package:flutter_datetime_picker/src/gree_route_date_picker_model.dart'; import 'package:flutter_datetime_picker/src/datetime_picker_theme.dart'; import 'package:flutter_datetime_picker/src/date_model.dart'; import 'package:flutter_datetime_picker/src/i18n_model.dart'; diff --git a/lib/src/GreeRouteDatePickerModel.dart b/lib/src/gree_route_date_picker_model.dart similarity index 100% rename from lib/src/GreeRouteDatePickerModel.dart rename to lib/src/gree_route_date_picker_model.dart From 8f5c2e8549260bb931f39f0b31395c648341eeed Mon Sep 17 00:00:00 2001 From: zh Date: Thu, 9 Mar 2023 09:06:59 +0800 Subject: [PATCH 6/9] =?UTF-8?q?[Mod]=20=E8=A7=A3=E5=86=B3=20=E6=9C=80?= =?UTF-8?q?=E5=B0=8F=20=E6=9C=80=E5=A4=A7=20=E6=97=B6=E9=97=B4=E4=B8=BA?= =?UTF-8?q?=E5=90=8C=E4=B8=80=E5=A4=A9=E7=9A=84=E6=98=BE=E7=A4=BAbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/lib/main.dart | 4 ++-- lib/src/gree_route_date_picker_model.dart | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 0928e2d5..e316366d 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -140,8 +140,8 @@ class HomePage extends StatelessWidget { DatePicker.showGreeRouteDateTimePicker( context, showTitleActions: true, - minTime: DateTime(2023, 3, 8, 16, 28), - maxTime: DateTime(2023, 3, 9, 2, 2), + minTime: DateTime(2023, 3, 8, 15, 3), + maxTime: DateTime(2023, 3, 9, 16, 4), theme: DatePickerTheme(title: '开始时间'), onChanged: (date) { print('change $date in time zone ' + date.timeZoneOffset.inHours.toString()); diff --git a/lib/src/gree_route_date_picker_model.dart b/lib/src/gree_route_date_picker_model.dart index 6d1c6154..960f09e8 100644 --- a/lib/src/gree_route_date_picker_model.dart +++ b/lib/src/gree_route_date_picker_model.dart @@ -18,6 +18,7 @@ class GreeRouteDatePickerModel extends DateTimePickerModel { @override String? middleStringAtIndex(int index) { String? hour = super.middleStringAtIndex(index); + /// 修复时间为同一天的显示bug if (isAtSameDay(maxTime, minTime)) { // hour @@ -34,13 +35,20 @@ class GreeRouteDatePickerModel extends DateTimePickerModel { String? minute = super.rightStringAtIndex(index); int hour = finalTime().hour; - /// 修复时间为同一天的显示bug + /// min max 为同一天 if (isAtSameDay(maxTime, minTime)) { if (hour < (maxTime?.hour ?? 0)) { return minute == null ? null : '$minute 分'; } - if (int.parse(minute ?? '0') <= (maxTime?.minute ?? 0) && int.parse(minute ?? '0') >= (minTime?.minute ?? 0)) { - return minute == null ? null : '$minute 分'; + + /// min hour 大于最小 minute + if ((minTime?.hour ?? 0) == hour) { + return int.parse(minute ?? '0') > (minTime?.minute ?? 0) ? '$minute 分' : null; + } + + /// max hour 小于最大 minute + if ((maxTime?.hour ?? 0) == hour && minute != null) { + return int.parse(minute ?? '0') <= (maxTime?.minute ?? 0) ? '$minute 分' : null; } return null; } From 1ce9d4dac58e8b740e7a8338f1f37635bbad9976 Mon Sep 17 00:00:00 2001 From: zh Date: Thu, 9 Mar 2023 09:34:34 +0800 Subject: [PATCH 7/9] =?UTF-8?q?[Mod]=20=E5=88=86=E9=92=9F=E6=98=BE?= =?UTF-8?q?=E7=A4=BAbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/lib/main.dart | 4 ++-- lib/src/gree_route_date_picker_model.dart | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index e316366d..996156db 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -140,8 +140,8 @@ class HomePage extends StatelessWidget { DatePicker.showGreeRouteDateTimePicker( context, showTitleActions: true, - minTime: DateTime(2023, 3, 8, 15, 3), - maxTime: DateTime(2023, 3, 9, 16, 4), + minTime: DateTime(2023, 3, 9, 8, 12), + maxTime: DateTime(2023, 3, 10, 7, 11), theme: DatePickerTheme(title: '开始时间'), onChanged: (date) { print('change $date in time zone ' + date.timeZoneOffset.inHours.toString()); diff --git a/lib/src/gree_route_date_picker_model.dart b/lib/src/gree_route_date_picker_model.dart index 960f09e8..321a7114 100644 --- a/lib/src/gree_route_date_picker_model.dart +++ b/lib/src/gree_route_date_picker_model.dart @@ -42,15 +42,19 @@ class GreeRouteDatePickerModel extends DateTimePickerModel { } /// min hour 大于最小 minute - if ((minTime?.hour ?? 0) == hour) { - return int.parse(minute ?? '0') > (minTime?.minute ?? 0) ? '$minute 分' : null; + if ((minTime?.hour ?? 0) == hour && minute != null) { + int _minute = int.parse(minute); + if (_minute >= (minTime?.minute ?? 0) && _minute <= (maxTime?.minute ?? 0)) { + return '$minute 分'; + } + return null; } /// max hour 小于最大 minute if ((maxTime?.hour ?? 0) == hour && minute != null) { - return int.parse(minute ?? '0') <= (maxTime?.minute ?? 0) ? '$minute 分' : null; + print('${int.parse(minute)} ${maxTime?.minute ?? 0} ${int.parse(minute) <= (maxTime?.minute ?? 0)}'); + return int.parse(minute) <= (maxTime?.minute ?? 0) ? '$minute 分' : null; } - return null; } return minute == null ? null : '$minute 分'; } From fe2290c4dfe7867fc468763bfd341965c2edffde Mon Sep 17 00:00:00 2001 From: zh Date: Mon, 20 Mar 2023 15:46:25 +0800 Subject: [PATCH 8/9] =?UTF-8?q?pop=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/ios/Flutter/flutter_export_environment.sh | 6 +++--- example/lib/main.dart | 6 +++++- lib/flutter_datetime_picker.dart | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh index 127d613c..a71e07fe 100755 --- a/example/ios/Flutter/flutter_export_environment.sh +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -1,9 +1,9 @@ #!/bin/sh # This is a generated file; do not edit or check into version control. export "FLUTTER_ROOT=/Users/zh/Library/flutter" -export "FLUTTER_APPLICATION_PATH=/Users/zh/Documents/gree/flutterProj/Fork/flutter_datetime_picker/example" +export "FLUTTER_APPLICATION_PATH=/Users/zh/Documents/gree/work/fork/flutter_datetime_picker/example" export "COCOAPODS_PARALLEL_CODE_SIGN=true" -export "FLUTTER_TARGET=/Users/zh/Documents/gree/flutterProj/Fork/flutter_datetime_picker/example/lib/main.dart" +export "FLUTTER_TARGET=/Users/zh/Documents/gree/work/fork/flutter_datetime_picker/example/lib/main.dart" export "FLUTTER_BUILD_DIR=build" export "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NUMBER=1" @@ -11,4 +11,4 @@ export "DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVF export "DART_OBFUSCATION=false" export "TRACK_WIDGET_CREATION=true" export "TREE_SHAKE_ICONS=false" -export "PACKAGE_CONFIG=/Users/zh/Documents/gree/flutterProj/Fork/flutter_datetime_picker/example/.dart_tool/package_config.json" +export "PACKAGE_CONFIG=/Users/zh/Documents/gree/work/fork/flutter_datetime_picker/example/.dart_tool/package_config.json" diff --git a/example/lib/main.dart b/example/lib/main.dart index 996156db..5c7bcdc8 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -150,7 +150,11 @@ class HomePage extends StatelessWidget { print('confirm $date'); }, locale: LocaleType.zh, - ); + ).then((date) { + + print('当前时间 $date'); + + }); }, child: Text( '导航 DatePicker', diff --git a/lib/flutter_datetime_picker.dart b/lib/flutter_datetime_picker.dart index 0cd1ee47..f470a62d 100644 --- a/lib/flutter_datetime_picker.dart +++ b/lib/flutter_datetime_picker.dart @@ -378,7 +378,7 @@ class _DatePickerState extends State<_DatePickerComponent> { style: theme.cancelStyle, ), onPressed: () { - Navigator.pop(context); + Navigator.pop(context, widget.pickerModel.finalTime()); if (widget.route.onCancel != null) { widget.route.onCancel!(); } From d22731033b54674187b34565e6f1bf1721b7bf2c Mon Sep 17 00:00:00 2001 From: zh Date: Mon, 20 Mar 2023 16:06:07 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E8=83=8C=E6=99=AF=E4=B8=8D=E5=8F=AF?= =?UTF-8?q?=E7=82=B9=E5=87=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/flutter_datetime_picker.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/flutter_datetime_picker.dart b/lib/flutter_datetime_picker.dart index f470a62d..20f43d2f 100644 --- a/lib/flutter_datetime_picker.dart +++ b/lib/flutter_datetime_picker.dart @@ -83,7 +83,7 @@ class _DatePickerRoute extends PopupRoute { Duration get transitionDuration => const Duration(milliseconds: 200); @override - bool get barrierDismissible => true; + bool get barrierDismissible => false; @override final String? barrierLabel;