diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml index e427d06..933a000 100644 --- a/.idea/libraries/Dart_Packages.xml +++ b/.idea/libraries/Dart_Packages.xml @@ -5,7 +5,7 @@ - @@ -19,7 +19,7 @@ - @@ -103,7 +103,7 @@ - @@ -124,14 +124,14 @@ - - @@ -159,14 +159,14 @@ - - @@ -201,7 +201,7 @@ - @@ -292,42 +292,42 @@ - - - - - - @@ -348,7 +348,7 @@ - @@ -397,7 +397,7 @@ - @@ -474,7 +474,7 @@ - @@ -509,7 +509,7 @@ - @@ -537,7 +537,7 @@ - @@ -551,7 +551,7 @@ - @@ -590,6 +590,20 @@ + + + + + + + + + + + + @@ -670,7 +684,7 @@ - @@ -684,7 +698,7 @@ - @@ -695,10 +709,17 @@ + + + + + + - @@ -726,7 +747,7 @@ - @@ -803,21 +824,21 @@ - - - @@ -845,7 +866,7 @@ - @@ -950,14 +971,14 @@ - - @@ -978,7 +999,7 @@ - @@ -1006,7 +1027,7 @@ - @@ -1027,7 +1048,7 @@ - @@ -1125,14 +1146,14 @@ - - @@ -1174,7 +1195,7 @@ - @@ -1188,21 +1209,21 @@ - - - @@ -1220,24 +1241,31 @@ + + + + + + - - - @@ -1251,14 +1279,14 @@ - - @@ -1300,9 +1328,9 @@ - + - + @@ -1314,21 +1342,21 @@ - + - - + + - - + + - + @@ -1340,16 +1368,22 @@ + + + + + + - + - + @@ -1358,23 +1392,25 @@ - + - + - + - + + + @@ -1386,15 +1422,16 @@ - + - + - + + - + @@ -1405,11 +1442,13 @@ - + + + - + @@ -1424,17 +1463,17 @@ - - + + - + - + - + @@ -1448,24 +1487,27 @@ - - + + - + - - - + + + - - - + + + + + + @@ -1475,16 +1517,6 @@ - - - - - - - - - - diff --git a/.idea/libraries/Flutter_Plugins.xml b/.idea/libraries/Flutter_Plugins.xml index ab8dd90..004eeb3 100644 --- a/.idea/libraries/Flutter_Plugins.xml +++ b/.idea/libraries/Flutter_Plugins.xml @@ -5,23 +5,17 @@ - - - - - - @@ -31,24 +25,38 @@ - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff --git a/example/lib/main.dart b/example/lib/main.dart index 06fa806..bf6f2c9 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -64,7 +64,7 @@ class _MyHomePageState extends State { tapAction: (value) { final startTime = value['startTime'] as DateTime?; setState(() { - _singleDateText = _formatDate(startTime); + _singleDateText = _formatDateWithWeekday(startTime); }); }, ), @@ -194,4 +194,14 @@ class _MyHomePageState extends State { dateTimeUtilsType: DateTimeUtilsType.yearMonthDay, ); } + + String _formatDateWithWeekday(DateTime? date) { + if (date == null) { + return '未选择'; + } + return '${DateTimeUtils.dateTimeUtilsTool( + dateTime: date.toIso8601String(), + dateTimeUtilsType: DateTimeUtilsType.yearMonthDayWord, + )} ${DateTimeUtils.getWeekDay(date)}'; + } } diff --git a/lib/calendarcalendar/calendar_choose_widget.dart b/lib/calendarcalendar/calendar_choose_widget.dart index 5a94536..0285889 100644 --- a/lib/calendarcalendar/calendar_choose_widget.dart +++ b/lib/calendarcalendar/calendar_choose_widget.dart @@ -83,38 +83,44 @@ class _CalendarChooseWidgetState extends State { String get dealTimeString { String? time = ""; if (endTime == null) { - time = DateTimeUtils.dateTimeUtilsTool( - dateTime: startTime.toString(), - dateTimeUtilsType: - widget.dateTimeUtilsType ?? DateTimeUtilsType.yearMonthDay, - ); + time = _formatDisplayDate(startTime); } else if (endTime == startTime) { - time = DateTimeUtils.dateTimeUtilsTool( - dateTime: startTime.toString(), - dateTimeUtilsType: - widget.dateTimeUtilsType ?? DateTimeUtilsType.yearMonthDay, - ); + time = _formatDisplayDate(startTime); } else { - time = "${DateTimeUtils.dateTimeUtilsTool( - dateTime: startTime.toString(), - dateTimeUtilsType: - widget.dateTimeUtilsType ?? DateTimeUtilsType.yearMonthDay, - )} - ${DateTimeUtils.dateTimeUtilsTool( - dateTime: endTime.toString(), - dateTimeUtilsType: - widget.dateTimeUtilsType ?? DateTimeUtilsType.yearMonthDay, - )}"; + time = + "${_formatDisplayDate(startTime)} - ${_formatDisplayDate(endTime)}"; } return time; } + String _formatDisplayDate(DateTime? dateTime) { + if (dateTime == null) { + return '-- --'; + } + final dateType = widget.dateTimeUtilsType ?? DateTimeUtilsType.yearMonthDay; + final formatted = DateTimeUtils.dateTimeUtilsTool( + dateTime: dateTime.toString(), + dateTimeUtilsType: dateType, + ); + if (widget.chooseIndex == 1 && + dateType == DateTimeUtilsType.yearMonthDayWord) { + return '$formatted ${DateTimeUtils.getWeekDay(dateTime)}'; + } + return formatted; + } + ///日历弹窗 onTapDate() { + final screenHeight = MediaQuery.of(context).size.height; + final singlePickerHeight = + screenHeight * 0.5 < 420 ? 420.0 : screenHeight * 0.5; + final rangePickerHeight = + screenHeight * 0.5 < 460 ? 460.0 : screenHeight * 0.5; if (widget.chooseIndex == 1) { ToastUtils.showBottomSheet( context: context, title: '选择时间', - height: MediaQuery.of(context).size.height / 2, + height: singlePickerHeight, isShowConfirm: true, contentWidget: CustomDatePicker( initialDate: DateTime.now(), @@ -131,7 +137,7 @@ class _CalendarChooseWidgetState extends State { ToastUtils.showBottomSheet( context: context, title: '选择时间', - height: MediaQuery.of(context).size.height / 2, + height: rangePickerHeight, isShowConfirm: true, contentWidget: CustomCalendarRangePickerWidget( firstDate: DateTime(DateTime.now().year - 2), diff --git a/lib/calendarcalendar/custom_calendar_range_picker_widget.dart b/lib/calendarcalendar/custom_calendar_range_picker_widget.dart index 6da89be..7eaa70e 100644 --- a/lib/calendarcalendar/custom_calendar_range_picker_widget.dart +++ b/lib/calendarcalendar/custom_calendar_range_picker_widget.dart @@ -867,6 +867,7 @@ class _DayHeaders extends StatelessWidget { ), child: GridView.custom( shrinkWrap: true, + padding: EdgeInsets.zero, gridDelegate: _monthItemGridDelegate, childrenDelegate: SliverChildListDelegate( labels, diff --git a/lib/utils/toast_utils.dart b/lib/utils/toast_utils.dart index 5ddce9f..a6d1058 100755 --- a/lib/utils/toast_utils.dart +++ b/lib/utils/toast_utils.dart @@ -67,16 +67,12 @@ class ToastUtils { context: context, builder: (BuildContext ctx) { final dialogHeight = height ?? MediaQuery.of(ctx).size.height / 2; - final bottomInset = MediaQuery.of(ctx).padding.bottom; return Material( type: MaterialType.transparency, child: Align( alignment: Alignment.bottomCenter, child: Container( width: double.infinity, - height: dialogHeight, - padding: (padding ?? const EdgeInsets.only(bottom: 40)) - .add(EdgeInsets.only(bottom: bottomInset)), decoration: const BoxDecoration( color: Colors.white, borderRadius: BorderRadius.only( @@ -84,79 +80,90 @@ class ToastUtils { topRight: Radius.circular(12), ), ), - child: Column( - children: [ - header ?? - Container( - padding: const EdgeInsets.only(bottom: 5), - decoration: const BoxDecoration( - border: Border( - bottom: BorderSide( - color: Color(0xffE1E1E1), - width: 0.5, - ), - ), - ), - child: Row( - children: [ - GestureDetector( - onTap: () => Navigator.of(ctx).pop(), - child: Container( - padding: - const EdgeInsets.only(left: 6, right: 10), - color: Colors.transparent, - child: Icon( - Icons.keyboard_arrow_down_rounded, - size: leftIconSize ?? 40, - ), - ), - ), - Expanded( - child: Container( - alignment: Alignment.center, - child: Text( - title ?? '头部', - style: TextStyle( - color: const Color(0xff333333), - fontSize: titleFontSize ?? 18, - fontWeight: FontWeight.bold, + child: SafeArea( + top: false, + child: SizedBox( + height: dialogHeight, + child: Padding( + padding: padding ?? EdgeInsets.zero, + child: Column( + children: [ + header ?? + Container( + padding: const EdgeInsets.only(bottom: 5), + decoration: const BoxDecoration( + border: Border( + bottom: BorderSide( + color: Color(0xffE1E1E1), + width: 0.5, ), ), ), - ), - GestureDetector( - onTap: () { - if (isShowConfirm) { - if (onConfirm != null) { - onConfirm(); - Navigator.of(ctx).pop(); - } - } - }, - child: Container( - padding: const EdgeInsets.only( - left: 10, - top: 8, - bottom: 8, - right: 18, - ), - alignment: Alignment.center, - color: Colors.transparent, - child: Text( - '确定', - style: TextStyle( - color: isShowConfirm - ? const Color(0xff4D6FD5) - : Colors.transparent, - fontSize: 16), - ), + child: Row( + children: [ + GestureDetector( + onTap: () => Navigator.of(ctx).pop(), + child: Container( + padding: const EdgeInsets.only( + left: 6, + right: 10, + ), + color: Colors.transparent, + child: Icon( + Icons.keyboard_arrow_down_rounded, + size: leftIconSize ?? 40, + ), + ), + ), + Expanded( + child: Container( + alignment: Alignment.center, + child: Text( + title ?? '头部', + style: TextStyle( + color: const Color(0xff333333), + fontSize: titleFontSize ?? 18, + fontWeight: FontWeight.bold, + ), + ), + ), + ), + GestureDetector( + onTap: () { + if (isShowConfirm) { + if (onConfirm != null) { + onConfirm(); + Navigator.of(ctx).pop(); + } + } + }, + child: Container( + padding: const EdgeInsets.only( + left: 10, + top: 8, + bottom: 8, + right: 18, + ), + alignment: Alignment.center, + color: Colors.transparent, + child: Text( + '确定', + style: TextStyle( + color: isShowConfirm + ? const Color(0xff4D6FD5) + : Colors.transparent, + fontSize: 16), + ), + ), + ) + ], ), - ) - ], - ), - ), - Expanded(child: contentWidget ?? const SizedBox()) - ], + ), + Expanded(child: contentWidget ?? const SizedBox()) + ], + ), + ), + ), ), ), ),