Skip to content

Commit e0617ac

Browse files
authored
fix(CupertinoDatePicker): font is inconsistent (flutter#162932)
This request fixes the issue where the missing font parameter for rendering the year caused its font to be inconsistent, leading to visual misalignment. https://github.com/flutter/flutter/blob/829fe68e9dffa8c9290afeeab8d1cf40b00e4f97/packages/flutter/lib/src/cupertino/date_picker.dart#L1454-L1461 - Fixes flutter#161773 ## 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.
1 parent ed71f92 commit e0617ac

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

packages/flutter/lib/src/cupertino/date_picker.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,7 @@ class _CupertinoDatePickerDateState extends State<CupertinoDatePicker> {
14581458
useMagnifier: _kUseMagnifier,
14591459
magnification: _kMagnification,
14601460
backgroundColor: widget.backgroundColor,
1461+
squeeze: _kSqueeze,
14611462
onSelectedItemChanged: (int index) {
14621463
selectedYear = index;
14631464
if (_isCurrentDateValid) {

packages/flutter/test/cupertino/date_picker_test.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,6 +2487,31 @@ void main() {
24872487
expect(testWidth, equals(largestWidth));
24882488
expect(widths.indexOf(largestWidth), equals(1));
24892489
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/39998
2490+
2491+
// Regression test for https://github.com/flutter/flutter/issues/161773
2492+
testWidgets('CupertinoDatePicker date value baseline alignment', (WidgetTester tester) async {
2493+
await tester.pumpWidget(
2494+
CupertinoApp(
2495+
home: Center(
2496+
child: SizedBox(
2497+
width: 400,
2498+
height: 400,
2499+
child: CupertinoDatePicker(
2500+
mode: CupertinoDatePickerMode.date,
2501+
onDateTimeChanged: (_) {},
2502+
initialDateTime: DateTime(2025, 2, 14),
2503+
),
2504+
),
2505+
),
2506+
),
2507+
);
2508+
2509+
Offset lastOffset = tester.getTopLeft(find.text('November'));
2510+
expect(tester.getTopLeft(find.text('11')).dy, lastOffset.dy);
2511+
2512+
lastOffset = tester.getTopLeft(find.text('11'));
2513+
expect(tester.getTopLeft(find.text('2022')).dy, lastOffset.dy);
2514+
});
24902515
}
24912516

24922517
Widget _buildPicker({

0 commit comments

Comments
 (0)