From b7e0dd6ff8d1d062edfc4cdfd8142d505aa30eba Mon Sep 17 00:00:00 2001 From: Sarbagya Dhaubanjar Date: Thu, 22 May 2025 03:13:29 +0545 Subject: [PATCH] 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. --- .../flutter/lib/src/material/date_picker.dart | 1 + .../test/material/date_range_picker_test.dart | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/packages/flutter/lib/src/material/date_picker.dart b/packages/flutter/lib/src/material/date_picker.dart index 455c97e5f4c..8d85cea443c 100644 --- a/packages/flutter/lib/src/material/date_picker.dart +++ b/packages/flutter/lib/src/material/date_picker.dart @@ -1259,6 +1259,7 @@ Future showDateRangePicker({ keyboardType: keyboardType, switchToInputEntryModeIcon: switchToInputEntryModeIcon, switchToCalendarEntryModeIcon: switchToCalendarEntryModeIcon, + calendarDelegate: calendarDelegate, ); if (textDirection != null) { diff --git a/packages/flutter/test/material/date_range_picker_test.dart b/packages/flutter/test/material/date_range_picker_test.dart index 92371173479..1157328c9b6 100644 --- a/packages/flutter/test/material/date_range_picker_test.dart +++ b/packages/flutter/test/material/date_range_picker_test.dart @@ -61,6 +61,7 @@ void main() { TextDirection textDirection = TextDirection.ltr, bool useMaterial3 = false, SelectableDayForRangePredicate? selectableDayPredicate, + CalendarDelegate 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()); }); + testWidgets('showDateRangePicker uses gregorian calendar delegate by default', ( + WidgetTester tester, + ) async { + await preparePicker(tester, (Future 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()); + }, useMaterial3: true); + }); + + testWidgets('showDateRangePicker using custom calendar delegate implementation', ( + WidgetTester tester, + ) async { + await preparePicker( + tester, + (Future 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()); + }, + useMaterial3: true, + calendarDelegate: const TestCalendarDelegate(), + ); + }); + testWidgets('Displays calendar based on the calendar delegate', (WidgetTester tester) async { Finder getMonthItem() { final Finder dayItem = find.descendant(