Skip to content

Commit

Permalink
6.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Macacoazul01 committed Dec 14, 2024
1 parent 8688cb9 commit 6cea26d
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 106 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 6.0.0 - 2024-12-14
- Added `PickerActionBarSettings` to handle the action bar settings of the dialog.
- [Breaking] `confirmWidget`, `cancelWidget`, `customDivider` are now on the `PickerActionBarSettings` class.
- [Breaking] renamed `PickerButtonsSettings` to `PickerDateButtonsSettings` and `buttonsSettings` to `dateButtonsSettings`.

## 5.2.0 - 2024-12-14
- Bumped intl to `0.20.0`. Fixes [#107](https://github.com/Macacoazul01/month_picker_dialog/issues/107).
- Bumped flutter_lints to `5.0.0`.
Expand Down
70 changes: 38 additions & 32 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,27 @@ class _MyAppState extends State<MyApp> {
}
return null;
},
confirmWidget: Text(
'This one!',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.indigo[300],
),
),
cancelWidget: Text(
'Cancel',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.red[900],
),
),
monthPickerDialogSettings: const MonthPickerDialogSettings(
headerSettings: PickerHeaderSettings(
monthPickerDialogSettings: MonthPickerDialogSettings(
headerSettings: const PickerHeaderSettings(
headerCurrentPageTextStyle: TextStyle(fontSize: 14),
headerSelectedIntervalTextStyle: TextStyle(fontSize: 16),
),
actionBarSettings: PickerActionBarSettings(
confirmWidget: Text(
'This one!',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.indigo[300],
),
),
cancelWidget: Text(
'Cancel',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.red[900],
),
),
),
),
).then((DateTime? date) {
if (date != null) {
Expand Down Expand Up @@ -144,27 +146,29 @@ class _MyAppState extends State<MyApp> {
lastDate: DateTime(DateTime.now().year + 8, 9),
initialRangeDate: DateTime(DateTime.now().year - 1, 5),
endRangeDate: DateTime(DateTime.now().year - 1, 7),
confirmWidget: Text(
'This one!',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.indigo[300],
),
),
cancelWidget: Text(
'Cancel',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.red[900],
),
),
headerTitle: const Text('Month Picker Dialog'),
monthPickerDialogSettings: MonthPickerDialogSettings(
dialogSettings: PickerDialogSettings(
locale: const Locale('en'),
dialogRoundedCornersRadius: 20,
dialogBackgroundColor: Colors.blueGrey[50],
),
actionBarSettings: PickerActionBarSettings(
confirmWidget: Text(
'This one!',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.indigo[300],
),
),
cancelWidget: Text(
'Cancel',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.red[900],
),
),
),
headerSettings: PickerHeaderSettings(
headerBackgroundColor: Colors.indigo[300],
headerSelectedIntervalTextStyle: const TextStyle(
Expand All @@ -178,7 +182,7 @@ class _MyAppState extends State<MyApp> {
previousIcon: Icons.arrow_back,
nextIcon: Icons.arrow_forward,
),
buttonsSettings: PickerButtonsSettings(
dateButtonsSettings: PickerDateButtonsSettings(
buttonBorder: const RoundedRectangleBorder(),
selectedMonthBackgroundColor: Colors.amber[900],
selectedMonthTextColor: Colors.white,
Expand All @@ -197,7 +201,9 @@ class _MyAppState extends State<MyApp> {
).then((List<DateTime>? dates) {
if (dates != null) {
print(dates);
print(dates.last.lastDayOfMonth());
if (dates.isNotEmpty) {
print(dates.last.lastDayOfMonth());
}
}
});
}
Expand Down
5 changes: 3 additions & 2 deletions lib/month_picker_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ export '/src/helpers/providers.dart';
export '/src/helpers/settings/dialog_settings.dart';
export '/src/helpers/settings/month_picker_settings.dart';
export '/src/helpers/settings/header_settings.dart';
export '/src/helpers/settings/buttons_settings.dart';
export '/src/helpers/settings/date_buttons_settings.dart';
export '/src/helpers/settings/action_bar_settings.dart';
export '/src/month_picker_dialog.dart';
export '/src/month_picker_widgets/button_bar.dart';
export 'src/month_picker_widgets/action_bar.dart';
export '/src/month_picker_widgets/header/header.dart';
export '/src/month_picker_widgets/header/header_arrows.dart';
export '/src/month_picker_widgets/header/header_row.dart';
Expand Down
4 changes: 0 additions & 4 deletions lib/src/helpers/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ class MonthpickerController {
this.selectableYearPredicate,
this.monthStylePredicate,
this.yearStylePredicate,
this.confirmWidget,
this.cancelWidget,
required this.theme,
required this.useMaterial3,
this.customDivider,
this.headerTitle,
this.rangeMode = false,
this.rangeList = false,
Expand All @@ -35,7 +32,6 @@ class MonthpickerController {
final ButtonStyle? Function(DateTime)? monthStylePredicate;
final ButtonStyle? Function(int)? yearStylePredicate;
final bool useMaterial3, rangeMode, rangeList, onlyYear;
final Widget? confirmWidget, cancelWidget, customDivider;
final Widget? headerTitle;
final MonthPickerDialogSettings monthPickerDialogSettings;

Expand Down
34 changes: 34 additions & 0 deletions lib/src/helpers/settings/action_bar_settings.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:flutter/widgets.dart';

///Class to hold all the customizations of the action bar part of the package.
class PickerActionBarSettings {
const PickerActionBarSettings({
this.buttonSpacing = 0,
this.confirmWidget,
this.cancelWidget,
this.customDivider,
});

/// The size of the current selected month/year circle.
///
/// default: `0`
final double buttonSpacing;

///The custom confirm widget of the dialog.
///
/// default: `null`
final Widget? confirmWidget;

///The custom cancel widget of the dialog.
///
/// default: `null`
final Widget? cancelWidget;

///The custom divider between the months/years and the confirm/cancel buttons.
///
/// default: `null`
final Widget? customDivider;
}

///The default settings for the buttons style.
const defaultPickerActionBarSettings = PickerActionBarSettings();
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/widgets.dart';

///Class to hold all the customizations of the buttons part of the package.
class PickerButtonsSettings {
const PickerButtonsSettings({
class PickerDateButtonsSettings {
const PickerDateButtonsSettings({
this.monthTextStyle,
TextStyle? yearTextStyle,
this.selectedMonthBackgroundColor,
Expand Down Expand Up @@ -77,4 +77,4 @@ class PickerButtonsSettings {
}

///The default settings for the buttons style.
const defaultPickerbuttonsSettings = PickerButtonsSettings();
const defaultPickerDateButtonsSettings = PickerDateButtonsSettings();
10 changes: 7 additions & 3 deletions lib/src/helpers/settings/month_picker_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class MonthPickerDialogSettings {
const MonthPickerDialogSettings({
this.dialogSettings = defaultPickerdialogSettings,
this.headerSettings = defaultPickerHeaderSettings,
this.buttonsSettings = defaultPickerbuttonsSettings,
this.dateButtonsSettings = defaultPickerDateButtonsSettings,
this.actionBarSettings = defaultPickerActionBarSettings,
});

///The customizations of the dialog part of the package.
Expand All @@ -14,8 +15,11 @@ class MonthPickerDialogSettings {
///The customizations of the header part of the package.
final PickerHeaderSettings headerSettings;

///The customizations of the buttons part of the package.
final PickerButtonsSettings buttonsSettings;
///The customizations of the date buttons part of the package.
final PickerDateButtonsSettings dateButtonsSettings;

///The customizations of the date buttons part of the package.
final PickerActionBarSettings actionBarSettings;
}

///The default settings for the month picker.
Expand Down
6 changes: 3 additions & 3 deletions lib/src/month_picker_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ class MonthPickerDialogState extends State<MonthPickerDialog> {
theme: widget.controller.theme,
controller: widget.controller,
),
if (widget.controller.customDivider != null)
widget.controller.customDivider!,
PickerButtonBar(
if (widget.controller.monthPickerDialogSettings.actionBarSettings.customDivider != null)
widget.controller.monthPickerDialogSettings.actionBarSettings.customDivider!,
PickerActionBar(
controller: widget.controller,
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
import '/month_picker_dialog.dart';

///The actions button bar. Where confirmation and cancel button are.
class PickerButtonBar extends StatelessWidget {
const PickerButtonBar({
class PickerActionBar extends StatelessWidget {
const PickerActionBar({
super.key,
required this.controller,
});
Expand All @@ -20,18 +20,19 @@ class PickerButtonBar extends StatelessWidget {
.monthPickerDialogSettings.dialogSettings.textScaleFactor!)
: null;
return OverflowBar(
spacing: controller.monthPickerDialogSettings.actionBarSettings.buttonSpacing,
children: <Widget>[
TextButton(
onPressed: () => controller.cancelFunction(context),
child: controller.cancelWidget ??
child: controller.monthPickerDialogSettings.actionBarSettings.cancelWidget ??
Text(
localizations.cancelButtonLabel,
textScaler: scaler,
),
),
TextButton(
onPressed: () => controller.okFunction(context),
child: controller.confirmWidget ??
child: controller.monthPickerDialogSettings.actionBarSettings.confirmWidget ??
Text(
localizations.okButtonLabel,
textScaler: scaler,
Expand Down
18 changes: 9 additions & 9 deletions lib/src/month_selector/month_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MonthButton extends StatelessWidget {
ButtonStyle _buildDefaultMonthStyle() {
Color? backgroundColor;
Color? foregroundColor = controller
.monthPickerDialogSettings.buttonsSettings.unselectedMonthsTextColor;
.monthPickerDialogSettings.dateButtonsSettings.unselectedMonthsTextColor;
final List<DateTime> selectedDates = [];

if (controller.rangeMode) {
Expand All @@ -69,14 +69,14 @@ class MonthButton extends StatelessWidget {
if (date.isAfter(selectedDates[0]) && date.isBefore(selectedDates[1])) {
backgroundColor = HSLColor.fromColor(controller
.monthPickerDialogSettings
.buttonsSettings
.dateButtonsSettings
.selectedMonthBackgroundColor ??
theme.colorScheme.secondary)
.withLightness(.7)
.toColor();
foregroundColor = theme.textTheme.labelLarge!
.copyWith(
color: controller.monthPickerDialogSettings.buttonsSettings
color: controller.monthPickerDialogSettings.dateButtonsSettings
.selectedMonthTextColor ??
theme.colorScheme.onSecondary,
)
Expand All @@ -88,29 +88,29 @@ class MonthButton extends StatelessWidget {
}

if (selectedDates.contains(date)) {
backgroundColor = controller.monthPickerDialogSettings.buttonsSettings
backgroundColor = controller.monthPickerDialogSettings.dateButtonsSettings
.selectedMonthBackgroundColor ??
theme.colorScheme.secondary;
foregroundColor = theme.textTheme.labelLarge!
.copyWith(
color: controller.monthPickerDialogSettings.buttonsSettings
color: controller.monthPickerDialogSettings.dateButtonsSettings
.selectedMonthTextColor ??
theme.colorScheme.onSecondary,
)
.color;
} else if (date.month == controller.now.month &&
date.year == controller.now.year) {
foregroundColor = controller.monthPickerDialogSettings.buttonsSettings
foregroundColor = controller.monthPickerDialogSettings.dateButtonsSettings
.currentMonthTextColor ??
backgroundColor;
}

return TextButton.styleFrom(
textStyle:
controller.monthPickerDialogSettings.buttonsSettings.monthTextStyle,
controller.monthPickerDialogSettings.dateButtonsSettings.monthTextStyle,
foregroundColor: foregroundColor,
backgroundColor: backgroundColor,
shape: controller.monthPickerDialogSettings.buttonsSettings.buttonBorder,
shape: controller.monthPickerDialogSettings.dateButtonsSettings.buttonBorder,
);
}

Expand All @@ -129,7 +129,7 @@ class MonthButton extends StatelessWidget {

return Padding(
padding: EdgeInsets.all(controller
.monthPickerDialogSettings.buttonsSettings.selectedDateRadius),
.monthPickerDialogSettings.dateButtonsSettings.selectedDateRadius),
child: TextButton(
onPressed: isEnabled
? () => onMonthSelected(DateTime(date.year, date.month))
Expand Down
12 changes: 0 additions & 12 deletions lib/src/pickers/show_month_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ import '/month_picker_dialog.dart';
///
/// `yearStylePredicate:` allows you to individually customize each year.
///
/// `confirmWidget:` lets you set a custom confirm widget.
///
/// `cancelWidget:` lets you set a custom cancel widget.
///
/// `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`).
Expand All @@ -40,9 +34,6 @@ Future<DateTime?> showMonthPicker({
bool Function(int)? selectableYearPredicate,
ButtonStyle? Function(DateTime)? monthStylePredicate,
ButtonStyle? Function(int)? yearStylePredicate,
Widget? confirmWidget,
Widget? cancelWidget,
Widget? customDivider,
Widget? headerTitle,
MonthPickerDialogSettings monthPickerDialogSettings =
defaultMonthPickerDialogSettings,
Expand All @@ -58,11 +49,8 @@ Future<DateTime?> showMonthPicker({
selectableYearPredicate: selectableYearPredicate,
monthStylePredicate: monthStylePredicate,
yearStylePredicate: yearStylePredicate,
confirmWidget: confirmWidget,
cancelWidget: cancelWidget,
theme: theme,
useMaterial3: theme.useMaterial3,
customDivider: customDivider,
headerTitle: headerTitle,
onlyYear: onlyYear,
);
Expand Down
Loading

0 comments on commit 6cea26d

Please sign in to comment.