From 4ad13800739f692dd5ccec9a06b243818ed19da4 Mon Sep 17 00:00:00 2001 From: Gianluca Bettega Date: Sun, 28 Jul 2024 21:38:33 -0300 Subject: [PATCH] format --- example/lib/main.dart | 3 +- lib/src/helpers/extensions.dart | 2 +- lib/src/helpers/settings/header_settings.dart | 2 +- .../settings/month_picker_settings.dart | 8 ++-- lib/src/month_picker_widgets/button_bar.dart | 9 ++-- .../month_picker_widgets/header/header.dart | 3 +- .../header/header_row.dart | 37 ++++++++++------ .../header/header_selected_date.dart | 6 +-- lib/src/month_picker_widgets/pager.dart | 3 +- lib/src/month_selector/month_button.dart | 43 ++++++++++++------- lib/src/month_selector/month_year_grid.dart | 8 ++-- lib/src/show_month_picker.dart | 10 ++--- lib/src/show_month_range_picker.dart | 9 ++-- lib/src/year_selector/year_button.dart | 8 ++-- lib/src/year_selector/year_grid.dart | 13 +++--- test/month_picker_dialog_test.dart | 4 +- 16 files changed, 99 insertions(+), 69 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 91252a2..5cdcf69 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -87,8 +87,7 @@ class _MyAppState extends State { initialDate: selectedDate ?? widget.initialDate, selectableMonthPredicate: (DateTime val) => val.month.isEven, - selectableYearPredicate: (int year) => - year.isEven, + selectableYearPredicate: (int year) => year.isEven, monthStylePredicate: (DateTime val) { if (val.month == 4) { return TextButton.styleFrom( diff --git a/lib/src/helpers/extensions.dart b/lib/src/helpers/extensions.dart index ed359e6..eaf8cc4 100644 --- a/lib/src/helpers/extensions.dart +++ b/lib/src/helpers/extensions.dart @@ -25,4 +25,4 @@ extension NullableDateTimeExtension on DateTime? { return this!.compareTo(end) < 0; } } -} \ No newline at end of file +} diff --git a/lib/src/helpers/settings/header_settings.dart b/lib/src/helpers/settings/header_settings.dart index 1888b46..5ec919e 100644 --- a/lib/src/helpers/settings/header_settings.dart +++ b/lib/src/helpers/settings/header_settings.dart @@ -58,7 +58,7 @@ class PickerHeaderSettings { final TextStyle? headerPageTextStyle; /// The space between the title widget and the current selected month/year/range text on the header. - /// + /// /// It will only appear if headerTitle widget isn't null. /// /// default: `5` diff --git a/lib/src/helpers/settings/month_picker_settings.dart b/lib/src/helpers/settings/month_picker_settings.dart index 8b1cffe..004119f 100644 --- a/lib/src/helpers/settings/month_picker_settings.dart +++ b/lib/src/helpers/settings/month_picker_settings.dart @@ -3,14 +3,14 @@ import 'package:month_picker_dialog/month_picker_dialog.dart'; ///Class to hold all the customizations of the date picker. class MonthPickerDialogSettings { const MonthPickerDialogSettings({ - this.dialogSettings = defaultPickerdialogSettings, + this.dialogSettings = defaultPickerdialogSettings, this.headerSettings = defaultPickerHeaderSettings, - this.buttonsSettings = defaultPickerbuttonsSettings, + this.buttonsSettings = defaultPickerbuttonsSettings, }); ///The customizations of the dialog part of the package. final PickerDialogSettings dialogSettings; - + ///The customizations of the header part of the package. final PickerHeaderSettings headerSettings; @@ -19,4 +19,4 @@ class MonthPickerDialogSettings { } ///The default settings for the month picker. -const defaultMonthPickerDialogSettings = MonthPickerDialogSettings(); \ No newline at end of file +const defaultMonthPickerDialogSettings = MonthPickerDialogSettings(); diff --git a/lib/src/month_picker_widgets/button_bar.dart b/lib/src/month_picker_widgets/button_bar.dart index 7760cdd..6ce5f3b 100644 --- a/lib/src/month_picker_widgets/button_bar.dart +++ b/lib/src/month_picker_widgets/button_bar.dart @@ -14,10 +14,11 @@ class PickerButtonBar extends StatelessWidget { final MaterialLocalizations localizations = MaterialLocalizations.of(context); final TextScaler? scaler = - controller.monthPickerDialogSettings.dialogSettings.textScaleFactor != null - ? TextScaler.linear( - controller.monthPickerDialogSettings.dialogSettings.textScaleFactor!) - : null; + controller.monthPickerDialogSettings.dialogSettings.textScaleFactor != + null + ? TextScaler.linear(controller + .monthPickerDialogSettings.dialogSettings.textScaleFactor!) + : null; return ButtonBar( children: [ TextButton( diff --git a/lib/src/month_picker_widgets/header/header.dart b/lib/src/month_picker_widgets/header/header.dart index a6cdac6..50bc19b 100644 --- a/lib/src/month_picker_widgets/header/header.dart +++ b/lib/src/month_picker_widgets/header/header.dart @@ -63,7 +63,8 @@ class PickerHeader extends StatelessWidget { if (controller.headerTitle != null) ...[ controller.headerTitle!, SizedBox( - height: controller.monthPickerDialogSettings.headerSettings.titleSpacing, + height: controller.monthPickerDialogSettings + .headerSettings.titleSpacing, ) ], HeaderSelectedDate( diff --git a/lib/src/month_picker_widgets/header/header_row.dart b/lib/src/month_picker_widgets/header/header_row.dart index d2e85a6..b6a74e9 100644 --- a/lib/src/month_picker_widgets/header/header_row.dart +++ b/lib/src/month_picker_widgets/header/header_row.dart @@ -23,14 +23,21 @@ class HeaderRow extends StatelessWidget { @override Widget build(BuildContext context) { - final TextStyle? headline5 = controller.monthPickerDialogSettings.headerSettings.headerPageTextStyle ?? theme.primaryTextTheme.headlineSmall; - final Color? arrowcolors = controller.monthPickerDialogSettings.headerSettings.headerIconsColor ?? (controller.monthPickerDialogSettings.headerSettings.headerPageTextStyle?.color ?? theme.primaryIconTheme.color); + final TextStyle? headline5 = controller + .monthPickerDialogSettings.headerSettings.headerPageTextStyle ?? + theme.primaryTextTheme.headlineSmall; + final Color? arrowcolors = + controller.monthPickerDialogSettings.headerSettings.headerIconsColor ?? + (controller.monthPickerDialogSettings.headerSettings + .headerPageTextStyle?.color ?? + theme.primaryIconTheme.color); final TextScaler? scaler = - controller.monthPickerDialogSettings.dialogSettings.textScaleFactor != null - ? TextScaler.linear( - controller.monthPickerDialogSettings.dialogSettings.textScaleFactor!) - : null; + controller.monthPickerDialogSettings.dialogSettings.textScaleFactor != + null + ? TextScaler.linear(controller + .monthPickerDialogSettings.dialogSettings.textScaleFactor!) + : null; final YearUpDownPageProvider yearProvider = Provider.of(context); @@ -53,9 +60,12 @@ class HeaderRow extends StatelessWidget { onDownButtonPressed: controller.onDownButtonPressed, downState: monthProvider.enableState.downState, upState: monthProvider.enableState.upState, - arrowSize: controller.monthPickerDialogSettings.headerSettings.headerIconsSize, - previousIcon: controller.monthPickerDialogSettings.headerSettings.previousIcon, - nextIcon: controller.monthPickerDialogSettings.headerSettings.nextIcon, + arrowSize: controller + .monthPickerDialogSettings.headerSettings.headerIconsSize, + previousIcon: controller + .monthPickerDialogSettings.headerSettings.previousIcon, + nextIcon: + controller.monthPickerDialogSettings.headerSettings.nextIcon, ), ] : [ @@ -87,9 +97,12 @@ class HeaderRow extends StatelessWidget { onDownButtonPressed: controller.onDownButtonPressed, downState: yearProvider.enableState.downState, upState: yearProvider.enableState.upState, - arrowSize: controller.monthPickerDialogSettings.headerSettings.headerIconsSize, - previousIcon: controller.monthPickerDialogSettings.headerSettings.previousIcon, - nextIcon: controller.monthPickerDialogSettings.headerSettings.nextIcon, + arrowSize: controller + .monthPickerDialogSettings.headerSettings.headerIconsSize, + previousIcon: controller + .monthPickerDialogSettings.headerSettings.previousIcon, + nextIcon: + controller.monthPickerDialogSettings.headerSettings.nextIcon, ), ]; return portrait diff --git a/lib/src/month_picker_widgets/header/header_selected_date.dart b/lib/src/month_picker_widgets/header/header_selected_date.dart index 8a7c5df..03b547e 100644 --- a/lib/src/month_picker_widgets/header/header_selected_date.dart +++ b/lib/src/month_picker_widgets/header/header_selected_date.dart @@ -23,9 +23,9 @@ class HeaderSelectedDate extends StatelessWidget { ? TextScaler.linear(controller .monthPickerDialogSettings.dialogSettings.textScaleFactor!) : null, - style: - controller.monthPickerDialogSettings.headerSettings.headerSelectedIntervalTextStyle ?? - theme.primaryTextTheme.titleMedium, + style: controller.monthPickerDialogSettings.headerSettings + .headerSelectedIntervalTextStyle ?? + theme.primaryTextTheme.titleMedium, ); } } diff --git a/lib/src/month_picker_widgets/pager.dart b/lib/src/month_picker_widgets/pager.dart index 3a70041..3850fb7 100644 --- a/lib/src/month_picker_widgets/pager.dart +++ b/lib/src/month_picker_widgets/pager.dart @@ -29,8 +29,7 @@ class PickerPager extends StatelessWidget { duration: Duration( milliseconds: controller.monthPickerDialogSettings.dialogSettings .scrollAnimationMilliseconds), - reverseDuration: - Duration( + reverseDuration: Duration( milliseconds: controller.monthPickerDialogSettings.dialogSettings .scrollAnimationMilliseconds), transitionBuilder: (Widget child, Animation animation) => diff --git a/lib/src/month_selector/month_button.dart b/lib/src/month_selector/month_button.dart index 109a563..b1ab08e 100644 --- a/lib/src/month_selector/month_button.dart +++ b/lib/src/month_selector/month_button.dart @@ -54,22 +54,27 @@ class MonthButton extends StatelessWidget { //TODO fix. Breaks predicate and range in the way it is today. // TextStyle? textStyle = controller.monthPickerDialogSettings.buttonsSettings.monthTextStyle ?? theme.textTheme.labelLarge; - Color? foregroundColor = controller.monthPickerDialogSettings.buttonsSettings.unselectedMonthsTextColor; + Color? foregroundColor = controller + .monthPickerDialogSettings.buttonsSettings.unselectedMonthsTextColor; final List selectedDates = [controller.selectedDate]; if (controller.rangeMode) { if (controller.firstRangeDate != null && controller.secondRangeDate != null) { - selectedDates.addAll([controller.firstRangeDate!, controller.secondRangeDate!]); + selectedDates + .addAll([controller.firstRangeDate!, controller.secondRangeDate!]); if (date.isAfter(selectedDates[1]) && date.isBefore(selectedDates[2])) { - backgroundColor = HSLColor.fromColor( - controller.monthPickerDialogSettings.buttonsSettings.selectedMonthBackgroundColor ?? - theme.colorScheme.secondary) + backgroundColor = HSLColor.fromColor(controller + .monthPickerDialogSettings + .buttonsSettings + .selectedMonthBackgroundColor ?? + theme.colorScheme.secondary) .withLightness(.7) .toColor(); foregroundColor = theme.textTheme.labelLarge! .copyWith( - color: controller.monthPickerDialogSettings.buttonsSettings.selectedMonthTextColor ?? + color: controller.monthPickerDialogSettings.buttonsSettings + .selectedMonthTextColor ?? theme.colorScheme.onSecondary, ) .color; @@ -78,17 +83,21 @@ class MonthButton extends StatelessWidget { } if (selectedDates.contains(date)) { - backgroundColor = controller.monthPickerDialogSettings.buttonsSettings.selectedMonthBackgroundColor ?? + backgroundColor = controller.monthPickerDialogSettings.buttonsSettings + .selectedMonthBackgroundColor ?? theme.colorScheme.secondary; foregroundColor = theme.textTheme.labelLarge! .copyWith( - color: controller.monthPickerDialogSettings.buttonsSettings.selectedMonthTextColor ?? + color: controller.monthPickerDialogSettings.buttonsSettings + .selectedMonthTextColor ?? theme.colorScheme.onSecondary, ) .color; } else if (date.month == controller.now.month && date.year == controller.now.year) { - foregroundColor = controller.monthPickerDialogSettings.buttonsSettings.currentMonthTextColor ?? backgroundColor; + foregroundColor = controller.monthPickerDialogSettings.buttonsSettings + .currentMonthTextColor ?? + backgroundColor; } return TextButton.styleFrom( @@ -113,23 +122,25 @@ class MonthButton extends StatelessWidget { } return Padding( - padding: EdgeInsets.all(controller.monthPickerDialogSettings.buttonsSettings.selectedDateRadius), + padding: EdgeInsets.all(controller + .monthPickerDialogSettings.buttonsSettings.selectedDateRadius), child: TextButton( onPressed: isEnabled ? () => onMonthSelected(DateTime(date.year, date.month)) : null, style: monthStyle, child: Text( - controller.monthPickerDialogSettings.dialogSettings.capitalizeFirstLetter + controller.monthPickerDialogSettings.dialogSettings + .capitalizeFirstLetter ? toBeginningOfSentenceCase( DateFormat.MMM(localeString).format(date))! : DateFormat.MMM(localeString).format(date).toLowerCase(), style: monthStyle.textStyle?.resolve({}), - textScaler: - controller.monthPickerDialogSettings.dialogSettings.textScaleFactor != - null - ? TextScaler.linear(controller - .monthPickerDialogSettings.dialogSettings.textScaleFactor!) + textScaler: controller.monthPickerDialogSettings.dialogSettings + .textScaleFactor != + null + ? TextScaler.linear(controller + .monthPickerDialogSettings.dialogSettings.textScaleFactor!) : null, ), ), diff --git a/lib/src/month_selector/month_year_grid.dart b/lib/src/month_selector/month_year_grid.dart index 5d3db31..b98df68 100644 --- a/lib/src/month_selector/month_year_grid.dart +++ b/lib/src/month_selector/month_year_grid.dart @@ -17,16 +17,16 @@ class MonthYearGridBuilder extends StatelessWidget { @override Widget build(BuildContext context) { return GridView.count( - physics: controller.monthPickerDialogSettings.dialogSettings.blockScrolling - ? const NeverScrollableScrollPhysics() - : const ClampingScrollPhysics(), + physics: + controller.monthPickerDialogSettings.dialogSettings.blockScrolling + ? const NeverScrollableScrollPhysics() + : const ClampingScrollPhysics(), padding: const EdgeInsets.all(8.0), crossAxisCount: 4, children: List.generate( 12, (final int index) => MonthButton( theme: controller.theme, - date: DateTime( controller.localFirstDate != null ? controller.localFirstDate!.year + page diff --git a/lib/src/show_month_picker.dart b/lib/src/show_month_picker.dart index b601f42..6b9dc28 100644 --- a/lib/src/show_month_picker.dart +++ b/lib/src/show_month_picker.dart @@ -12,7 +12,7 @@ import '/month_picker_dialog.dart'; /// `lastDate:` is the optional upper bound for month selection. /// /// `selectableMonthPredicate:` lets you control enabled months just like the official selectableDayPredicate. -/// +/// /// `selectableYearPredicate:` lets you control enabled years just like the official selectableDayPredicate. /// /// `monthStylePredicate:` allows you to individually customize each month. @@ -26,7 +26,7 @@ import '/month_picker_dialog.dart'; /// `customDivider:` lets you add a custom divider between the months/years and the confirm/cancel buttons. /// /// `headerTitle:` lets you add a custom title to the header of the dialog (default is `null`). -/// +/// /// `monthPickerDialogSettings:` is the object that will hold all of the style of the picker dialog (default is `defaultMonthPickerDialogSettings`). /// Future showMonthPicker({ @@ -42,7 +42,8 @@ Future showMonthPicker({ Widget? cancelWidget, Widget? customDivider, Widget? headerTitle, - MonthPickerDialogSettings monthPickerDialogSettings = defaultMonthPickerDialogSettings, + MonthPickerDialogSettings monthPickerDialogSettings = + defaultMonthPickerDialogSettings, }) async { final ThemeData theme = Theme.of(context); final MonthpickerController controller = MonthpickerController( @@ -65,8 +66,7 @@ Future showMonthPicker({ ); final DateTime? dialogDate = await showDialog( context: context, - barrierDismissible: - monthPickerDialogSettings.dialogSettings.dismissible, + barrierDismissible: monthPickerDialogSettings.dialogSettings.dismissible, builder: (BuildContext context) { return MultiProvider( providers: [ diff --git a/lib/src/show_month_range_picker.dart b/lib/src/show_month_range_picker.dart index 2e59323..ab27e3e 100644 --- a/lib/src/show_month_range_picker.dart +++ b/lib/src/show_month_range_picker.dart @@ -12,7 +12,7 @@ import '/month_picker_dialog.dart'; /// `lastDate:` is the optional upper bound for month selection. /// /// `selectableMonthPredicate:` lets you control enabled months just like the official selectableDayPredicate. -/// +/// /// `selectableYearPredicate:` lets you control enabled months just like the official selectableDayPredicate. /// /// `monthStylePredicate:` allows you to individually customize each month. @@ -26,7 +26,7 @@ import '/month_picker_dialog.dart'; /// `customDivider:` lets you add a custom divider between the months/years and the confirm/cancel buttons. /// /// `headerTitle:` lets you add a custom title to the header of the dialog (default is `null`). -/// +/// /// `monthPickerDialogSettings:` is the object that will hold all of the style of the picker dialog (default is `defaultMonthPickerDialogSettings`). /// /// `rangeList:` lets you define if the controller will return the full list of months between the two selected or only them (default is `false`). @@ -45,7 +45,8 @@ Future?> showMonthRangePicker({ Widget? customDivider, Widget? headerTitle, bool rangeList = false, - MonthPickerDialogSettings monthPickerDialogSettings = defaultMonthPickerDialogSettings, + MonthPickerDialogSettings monthPickerDialogSettings = + defaultMonthPickerDialogSettings, }) async { final ThemeData theme = Theme.of(context); final MonthpickerController controller = MonthpickerController( @@ -63,7 +64,7 @@ Future?> showMonthRangePicker({ customDivider: customDivider, headerTitle: headerTitle, rangeMode: true, - rangeList: rangeList, + rangeList: rangeList, monthPickerDialogSettings: monthPickerDialogSettings, ); final List? dialogDate = await showDialog>( diff --git a/lib/src/year_selector/year_button.dart b/lib/src/year_selector/year_button.dart index 3b67f46..499d08b 100644 --- a/lib/src/year_selector/year_button.dart +++ b/lib/src/year_selector/year_button.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import '/month_picker_dialog.dart'; + ///The button to be used on the grid of years. class YearButton extends StatelessWidget { const YearButton({ @@ -36,7 +37,9 @@ class YearButton extends StatelessWidget { } if (localFirstDate != null) { if (localLastDate != null) { - return year >= localFirstDate.year && year <= localLastDate.year && _holdsSelectionPredicate(year); + return year >= localFirstDate.year && + year <= localLastDate.year && + _holdsSelectionPredicate(year); } else { return year >= localFirstDate.year && _holdsSelectionPredicate(year); } @@ -72,8 +75,7 @@ class YearButton extends StatelessWidget { backgroundColor) : controller.monthPickerDialogSettings.buttonsSettings .unselectedYearsTextColor, - backgroundColor: - isTheSelectedYear ? backgroundColor : null, + backgroundColor: isTheSelectedYear ? backgroundColor : null, shape: controller.monthPickerDialogSettings.buttonsSettings.buttonBorder, ); return yearStyle; diff --git a/lib/src/year_selector/year_grid.dart b/lib/src/year_selector/year_grid.dart index 1fbeb16..40a581d 100644 --- a/lib/src/year_selector/year_grid.dart +++ b/lib/src/year_selector/year_grid.dart @@ -15,13 +15,14 @@ class YearGrid extends StatelessWidget { @override Widget build(BuildContext context) { - final String localeString = - getLocale(context, - selectedLocale: controller.monthPickerDialogSettings.dialogSettings.locale); + final String localeString = getLocale(context, + selectedLocale: + controller.monthPickerDialogSettings.dialogSettings.locale); return GridView.count( - physics: controller.monthPickerDialogSettings.dialogSettings.blockScrolling - ? const NeverScrollableScrollPhysics() - : const ClampingScrollPhysics(), + physics: + controller.monthPickerDialogSettings.dialogSettings.blockScrolling + ? const NeverScrollableScrollPhysics() + : const ClampingScrollPhysics(), padding: const EdgeInsets.all(8.0), crossAxisCount: 4, children: List.generate( diff --git a/test/month_picker_dialog_test.dart b/test/month_picker_dialog_test.dart index 8b5483b..493fe12 100644 --- a/test/month_picker_dialog_test.dart +++ b/test/month_picker_dialog_test.dart @@ -66,7 +66,9 @@ void main() { expect(controller.localLastDate, DateTime(2027)); controller.firstPossibleMonth(2120); expect(controller.selectedDate, DateTime(2120, 2)); - expect(controller.monthPickerDialogSettings.buttonsSettings.selectedDateRadius, 1); + expect( + controller.monthPickerDialogSettings.buttonsSettings.selectedDateRadius, + 1); expect(controller.monthPickerDialogSettings.dialogSettings.forcePortrait, true); expect(controller.rangeMode, true);