Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
Macacoazul01 committed Jul 29, 2024
1 parent 39886d2 commit 4ad1380
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 69 deletions.
3 changes: 1 addition & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ class _MyAppState extends State<MyApp> {
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(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/helpers/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ extension NullableDateTimeExtension on DateTime? {
return this!.compareTo(end) < 0;
}
}
}
}
2 changes: 1 addition & 1 deletion lib/src/helpers/settings/header_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
8 changes: 4 additions & 4 deletions lib/src/helpers/settings/month_picker_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -19,4 +19,4 @@ class MonthPickerDialogSettings {
}

///The default settings for the month picker.
const defaultMonthPickerDialogSettings = MonthPickerDialogSettings();
const defaultMonthPickerDialogSettings = MonthPickerDialogSettings();
9 changes: 5 additions & 4 deletions lib/src/month_picker_widgets/button_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: <Widget>[
TextButton(
Expand Down
3 changes: 2 additions & 1 deletion lib/src/month_picker_widgets/header/header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
37 changes: 25 additions & 12 deletions lib/src/month_picker_widgets/header/header_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<YearUpDownPageProvider>(context);
Expand All @@ -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,
),
]
: <Widget>[
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/src/month_picker_widgets/header/header_selected_date.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}
3 changes: 1 addition & 2 deletions lib/src/month_picker_widgets/pager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> animation) =>
Expand Down
43 changes: 27 additions & 16 deletions lib/src/month_selector/month_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<DateTime> 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;
Expand All @@ -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(
Expand All @@ -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,
),
),
Expand Down
8 changes: 4 additions & 4 deletions lib/src/month_selector/month_year_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Widget>.generate(
12,
(final int index) => MonthButton(
theme: controller.theme,

date: DateTime(
controller.localFirstDate != null
? controller.localFirstDate!.year + page
Expand Down
10 changes: 5 additions & 5 deletions lib/src/show_month_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<DateTime?> showMonthPicker({
Expand All @@ -42,7 +42,8 @@ Future<DateTime?> showMonthPicker({
Widget? cancelWidget,
Widget? customDivider,
Widget? headerTitle,
MonthPickerDialogSettings monthPickerDialogSettings = defaultMonthPickerDialogSettings,
MonthPickerDialogSettings monthPickerDialogSettings =
defaultMonthPickerDialogSettings,
}) async {
final ThemeData theme = Theme.of(context);
final MonthpickerController controller = MonthpickerController(
Expand All @@ -65,8 +66,7 @@ Future<DateTime?> showMonthPicker({
);
final DateTime? dialogDate = await showDialog<DateTime?>(
context: context,
barrierDismissible:
monthPickerDialogSettings.dialogSettings.dismissible,
barrierDismissible: monthPickerDialogSettings.dialogSettings.dismissible,
builder: (BuildContext context) {
return MultiProvider(
providers: [
Expand Down
9 changes: 5 additions & 4 deletions lib/src/show_month_range_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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`).
Expand All @@ -45,7 +45,8 @@ Future<List<DateTime>?> 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(
Expand All @@ -63,7 +64,7 @@ Future<List<DateTime>?> showMonthRangePicker({
customDivider: customDivider,
headerTitle: headerTitle,
rangeMode: true,
rangeList: rangeList,
rangeList: rangeList,
monthPickerDialogSettings: monthPickerDialogSettings,
);
final List<DateTime>? dialogDate = await showDialog<List<DateTime>>(
Expand Down
8 changes: 5 additions & 3 deletions lib/src/year_selector/year_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 7 additions & 6 deletions lib/src/year_selector/year_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Widget>.generate(
Expand Down
Loading

0 comments on commit 4ad1380

Please sign in to comment.