Respect calendarDelegate in showDateRangePicker (#168290)

This PR fixes an issue where the `calendarDelegate` parameter was not
respected by `showDateRangePicker`. Although support
for`calendarDelegate` was added in [PR
#161874](https://github.com/flutter/flutter/pull/161874), it was
inadvertently omitted from `showDateRangePicker`, causing
inconsistencies in behavior compared to `showDatePicker`.

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
This commit is contained in:
Sarbagya Dhaubanjar 2025-05-22 03:13:29 +05:45 committed by GitHub
parent f9795d6f2d
commit b7e0dd6ff8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 0 deletions

View File

@ -1259,6 +1259,7 @@ Future<DateTimeRange?> showDateRangePicker({
keyboardType: keyboardType,
switchToInputEntryModeIcon: switchToInputEntryModeIcon,
switchToCalendarEntryModeIcon: switchToCalendarEntryModeIcon,
calendarDelegate: calendarDelegate,
);
if (textDirection != null) {

View File

@ -61,6 +61,7 @@ void main() {
TextDirection textDirection = TextDirection.ltr,
bool useMaterial3 = false,
SelectableDayForRangePredicate? selectableDayPredicate,
CalendarDelegate<DateTime> calendarDelegate = const GregorianCalendarDelegate(),
}) async {
late BuildContext buttonContext;
await tester.pumpWidget(
@ -106,6 +107,7 @@ void main() {
builder: (BuildContext context, Widget? child) {
return Directionality(textDirection: textDirection, child: child ?? const SizedBox());
},
calendarDelegate: calendarDelegate,
);
await tester.pumpAndSettle(const Duration(seconds: 1));
@ -1868,6 +1870,49 @@ void main() {
expect(dialog.calendarDelegate, isA<TestCalendarDelegate>());
});
testWidgets('showDateRangePicker uses gregorian calendar delegate by default', (
WidgetTester tester,
) async {
await preparePicker(tester, (Future<DateTimeRange?> range) async {
final Finder helpText = find.text('Select range');
final Finder firstDateHeaderText = find.text('Jan 15');
final Finder lastDateHeaderText = find.text('Jan 25, 2016');
final Finder saveText = find.text('Save');
expect(helpText, findsOneWidget);
expect(firstDateHeaderText, findsOneWidget);
expect(lastDateHeaderText, findsOneWidget);
expect(saveText, findsOneWidget);
final DateRangePickerDialog dialog = tester.widget(find.byType(DateRangePickerDialog));
expect(dialog.calendarDelegate, isA<GregorianCalendarDelegate>());
}, useMaterial3: true);
});
testWidgets('showDateRangePicker using custom calendar delegate implementation', (
WidgetTester tester,
) async {
await preparePicker(
tester,
(Future<DateTimeRange?> range) async {
final Finder helpText = find.text('Select range');
final Finder firstDateHeaderText = find.text('Jan 15');
final Finder lastDateHeaderText = find.text('Jan 25, 2016');
final Finder saveText = find.text('Save');
expect(helpText, findsOneWidget);
expect(firstDateHeaderText, findsOneWidget);
expect(lastDateHeaderText, findsOneWidget);
expect(saveText, findsOneWidget);
final DateRangePickerDialog dialog = tester.widget(find.byType(DateRangePickerDialog));
expect(dialog.calendarDelegate, isA<TestCalendarDelegate>());
},
useMaterial3: true,
calendarDelegate: const TestCalendarDelegate(),
);
});
testWidgets('Displays calendar based on the calendar delegate', (WidgetTester tester) async {
Finder getMonthItem() {
final Finder dayItem = find.descendant(