Skip to content

Commit 90a8922

Browse files
albinpkdkwingsmthuycozy
authored
fix: selected date decorator renders outside PageView in DatePickerDialog dialog (flutter#171718)
Wraps `PageView` with a transparent `Material` to ensure the selected date decorator is painted in the correct context, avoiding visual glitches during transitions. Fixes flutter#171717 ## 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. - [ ] 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]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: Tong Mu <[email protected]> Co-authored-by: Huy <[email protected]>
1 parent f8e8a8d commit 90a8922

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

packages/flutter/lib/src/material/calendar_date_picker.dart

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import 'icon_button.dart';
2121
import 'icons.dart';
2222
import 'ink_decoration.dart';
2323
import 'ink_well.dart';
24+
import 'material.dart';
2425
import 'material_localizations.dart';
2526
import 'material_state.dart';
2627
import 'theme.dart';
@@ -888,13 +889,18 @@ class _MonthPickerState extends State<_MonthPicker> {
888889
child: _FocusedDate(
889890
calendarDelegate: widget.calendarDelegate,
890891
date: _dayGridFocus.hasFocus ? _focusedDay : null,
891-
child: PageView.builder(
892-
key: _pageViewKey,
893-
controller: _pageController,
894-
itemBuilder: _buildItems,
895-
itemCount:
896-
widget.calendarDelegate.monthDelta(widget.firstDate, widget.lastDate) + 1,
897-
onPageChanged: _handleMonthPageChanged,
892+
// Wrap the PageView with `Material`, so when its child paints on materials
893+
// the content won't go out of boundary during page transition.
894+
child: Material(
895+
type: MaterialType.transparency,
896+
child: PageView.builder(
897+
key: _pageViewKey,
898+
controller: _pageController,
899+
itemBuilder: _buildItems,
900+
itemCount:
901+
widget.calendarDelegate.monthDelta(widget.firstDate, widget.lastDate) + 1,
902+
onPageChanged: _handleMonthPageChanged,
903+
),
898904
),
899905
),
900906
),

packages/flutter/test/material/calendar_date_picker_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,29 @@ void main() {
14351435
),
14361436
);
14371437
});
1438+
1439+
testWidgets('Ink feature paints on inner Material', (WidgetTester tester) async {
1440+
await tester.pumpWidget(
1441+
calendarDatePicker(
1442+
firstDate: DateTime(2025, DateTime.june),
1443+
initialDate: DateTime(2025, DateTime.july, 20),
1444+
lastDate: DateTime(2025, DateTime.august, 31),
1445+
),
1446+
);
1447+
1448+
// Material outside the PageView.
1449+
final MaterialInkController outerMaterial = Material.of(
1450+
tester.element(find.byType(FocusableActionDetector)),
1451+
);
1452+
// Material directly wrapping the PageView.
1453+
final MaterialInkController innerMaterial = Material.of(
1454+
tester.element(find.byType(PageView)),
1455+
);
1456+
1457+
// Only the inner Material should have ink features.
1458+
expect((outerMaterial as dynamic).debugInkFeatures, isNull);
1459+
expect((innerMaterial as dynamic).debugInkFeatures, hasLength(31));
1460+
});
14381461
});
14391462

14401463
group('YearPicker', () {

0 commit comments

Comments
 (0)