Skip to content

Commit f83d086

Browse files
committed
6.3.0
1 parent 417c367 commit f83d086

File tree

7 files changed

+66
-42
lines changed

7 files changed

+66
-42
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 6.3.0 - 2025-07-04
2+
- Added `onYearSelected` and `onMonthSelected` functions to provide a callback after the user selects a value.
3+
14
## 6.2.5 - 2025-07-04
25
- Added copyWith Method to picker settings. Tks [nomoruyi](https://github.com/nomoruyi).
36

example/lib/main.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ class _MyAppState extends State<MyApp> {
205205
),
206206
),
207207
rangeList: true,
208+
onMonthSelected: (DateTime date) {
209+
print('Selected month: ${date.toIso8601String()}');
210+
},
211+
onYearSelected: (int date) {
212+
print('Selected year: $date');
213+
},
208214
).then((List<DateTime>? dates) {
209215
if (dates != null && dates.isNotEmpty) {
210216
setState(() {

lib/src/month_picker_dialog.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class MonthPickerDialogState extends State<MonthPickerDialog> {
201201
);
202202
},
203203
);
204-
if (widget.controller.onYearSelected != null) {
204+
if (widget.controller.onMonthSelected != null) {
205205
widget.controller.onMonthSelected!(date);
206206
}
207207
}

lib/src/pickers/show_month_picker.dart

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//TODO let the user pass a custom controller to the dialog
2-
//TODO remake the controller docs
31
import 'package:flutter/material.dart';
42
import 'package:provider/provider.dart';
53

@@ -27,6 +25,10 @@ import '/month_picker_dialog.dart';
2725
///
2826
/// `onlyYear:` Displays only year picker dialog. Prefer to use `showYearPicker` instead of `showMonthPicker` with this parameter set to `true` to avoid unnecessary parameters.
2927
///
28+
/// `onYearSelected:` the function that triggers after the user selected an year (default is `null`).
29+
///
30+
/// `onMonthSelected:` the function that triggers after the user selected a month (default is `null`).
31+
///
3032
Future<DateTime?> showMonthPicker({
3133
required BuildContext context,
3234
DateTime? initialDate,
@@ -40,22 +42,25 @@ Future<DateTime?> showMonthPicker({
4042
MonthPickerDialogSettings monthPickerDialogSettings =
4143
defaultMonthPickerDialogSettings,
4244
bool onlyYear = false,
45+
Function(DateTime)? onMonthSelected,
46+
Function(int)? onYearSelected,
4347
}) async {
4448
final ThemeData theme = Theme.of(context);
4549
final MonthpickerController controller = MonthpickerController(
46-
initialDate: initialDate,
47-
firstDate: firstDate,
48-
lastDate: lastDate,
49-
monthPickerDialogSettings: monthPickerDialogSettings,
50-
selectableMonthPredicate: selectableMonthPredicate,
51-
selectableYearPredicate: selectableYearPredicate,
52-
monthStylePredicate: monthStylePredicate,
53-
yearStylePredicate: yearStylePredicate,
54-
theme: theme,
55-
useMaterial3: theme.useMaterial3,
56-
headerTitle: headerTitle,
57-
onlyYear: onlyYear,
58-
);
50+
initialDate: initialDate,
51+
firstDate: firstDate,
52+
lastDate: lastDate,
53+
monthPickerDialogSettings: monthPickerDialogSettings,
54+
selectableMonthPredicate: selectableMonthPredicate,
55+
selectableYearPredicate: selectableYearPredicate,
56+
monthStylePredicate: monthStylePredicate,
57+
yearStylePredicate: yearStylePredicate,
58+
theme: theme,
59+
useMaterial3: theme.useMaterial3,
60+
headerTitle: headerTitle,
61+
onlyYear: onlyYear,
62+
onMonthSelected: onMonthSelected,
63+
onYearSelected: onYearSelected);
5964
controller.initialize();
6065
final DateTime? dialogDate = await showDialog<DateTime?>(
6166
context: context,

lib/src/pickers/show_month_range_picker.dart

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ import '/month_picker_dialog.dart';
2727
///
2828
/// `rangeList:` defines if the controller will return the full list of months between the two selected or only them (default is `false`).
2929
///
30+
/// `onYearSelected:` the function that triggers after the user selected an year (default is `null`).
31+
///
32+
/// `onMonthSelected:` the function that triggers after the user selected a month (default is `null`).
33+
///
3034
Future<List<DateTime>?> showMonthRangePicker({
3135
required BuildContext context,
3236
DateTime? initialRangeDate,
@@ -39,26 +43,29 @@ Future<List<DateTime>?> showMonthRangePicker({
3943
ButtonStyle? Function(int)? yearStylePredicate,
4044
Widget? headerTitle,
4145
bool rangeList = false,
46+
Function(DateTime)? onMonthSelected,
47+
Function(int)? onYearSelected,
4248
MonthPickerDialogSettings monthPickerDialogSettings =
4349
defaultMonthPickerDialogSettings,
4450
}) async {
4551
final ThemeData theme = Theme.of(context);
4652
final MonthpickerController controller = MonthpickerController(
47-
initialRangeDate: initialRangeDate.firstDayOfMonth(),
48-
endRangeDate: endRangeDate.firstDayOfMonth(),
49-
firstDate: firstDate,
50-
lastDate: lastDate,
51-
selectableMonthPredicate: selectableMonthPredicate,
52-
selectableYearPredicate: selectableYearPredicate,
53-
monthStylePredicate: monthStylePredicate,
54-
yearStylePredicate: yearStylePredicate,
55-
theme: theme,
56-
useMaterial3: theme.useMaterial3,
57-
headerTitle: headerTitle,
58-
rangeMode: true,
59-
rangeList: rangeList,
60-
monthPickerDialogSettings: monthPickerDialogSettings,
61-
);
53+
initialRangeDate: initialRangeDate.firstDayOfMonth(),
54+
endRangeDate: endRangeDate.firstDayOfMonth(),
55+
firstDate: firstDate,
56+
lastDate: lastDate,
57+
selectableMonthPredicate: selectableMonthPredicate,
58+
selectableYearPredicate: selectableYearPredicate,
59+
monthStylePredicate: monthStylePredicate,
60+
yearStylePredicate: yearStylePredicate,
61+
theme: theme,
62+
useMaterial3: theme.useMaterial3,
63+
headerTitle: headerTitle,
64+
rangeMode: true,
65+
rangeList: rangeList,
66+
monthPickerDialogSettings: monthPickerDialogSettings,
67+
onMonthSelected: onMonthSelected,
68+
onYearSelected: onYearSelected);
6269
controller.initialize();
6370
final List<DateTime>? dialogDate = await showDialog<List<DateTime>>(
6471
context: context,

lib/src/pickers/show_year_picker.dart

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import '/month_picker_dialog.dart';
1818
///
1919
/// `monthPickerDialogSettings:` holds all the style of the picker dialog (default is `defaultMonthPickerDialogSettings`).
2020
///
21+
/// `onYearSelected:` the function that triggers after the user selected an year (default is `null`).
22+
///
2123
Future<int?> showYearPicker({
2224
required BuildContext context,
2325
DateTime? initialDate,
@@ -28,18 +30,19 @@ Future<int?> showYearPicker({
2830
Widget? headerTitle,
2931
MonthPickerDialogSettings monthPickerDialogSettings =
3032
defaultMonthPickerDialogSettings,
33+
Function(int)? onYearSelected,
3134
}) async {
3235
final DateTime? monthPickerDate = await showMonthPicker(
33-
context: context,
34-
initialDate: initialDate,
35-
firstDate: firstDate,
36-
lastDate: lastDate,
37-
selectableYearPredicate: selectableYearPredicate,
38-
yearStylePredicate: yearStylePredicate,
39-
headerTitle: headerTitle,
40-
monthPickerDialogSettings: monthPickerDialogSettings,
41-
onlyYear: true,
42-
);
36+
context: context,
37+
initialDate: initialDate,
38+
firstDate: firstDate,
39+
lastDate: lastDate,
40+
selectableYearPredicate: selectableYearPredicate,
41+
yearStylePredicate: yearStylePredicate,
42+
headerTitle: headerTitle,
43+
monthPickerDialogSettings: monthPickerDialogSettings,
44+
onlyYear: true,
45+
onYearSelected: onYearSelected);
4346

4447
return monthPickerDate?.year;
4548
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: month_picker_dialog
22
description: Internationalized dialog for picking a single month from an infinite list of years.
3-
version: 6.2.5
3+
version: 6.3.0
44
homepage: https://github.com/Macacoazul01/month_picker_dialog
55

66
environment:

0 commit comments

Comments
 (0)