From e0617ac3621758464386a0f97d985b2fe498b1cc Mon Sep 17 00:00:00 2001 From: StanleyCocos Date: Fri, 21 Feb 2025 06:26:55 +0800 Subject: [PATCH] fix(CupertinoDatePicker): font is inconsistent (#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 https://github.com/flutter/flutter/issues/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. --- .../lib/src/cupertino/date_picker.dart | 1 + .../test/cupertino/date_picker_test.dart | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/packages/flutter/lib/src/cupertino/date_picker.dart b/packages/flutter/lib/src/cupertino/date_picker.dart index bb799a0747..a03adc503e 100644 --- a/packages/flutter/lib/src/cupertino/date_picker.dart +++ b/packages/flutter/lib/src/cupertino/date_picker.dart @@ -1458,6 +1458,7 @@ class _CupertinoDatePickerDateState extends State { useMagnifier: _kUseMagnifier, magnification: _kMagnification, backgroundColor: widget.backgroundColor, + squeeze: _kSqueeze, onSelectedItemChanged: (int index) { selectedYear = index; if (_isCurrentDateValid) { diff --git a/packages/flutter/test/cupertino/date_picker_test.dart b/packages/flutter/test/cupertino/date_picker_test.dart index 1e5b3da4c2..0d21093af8 100644 --- a/packages/flutter/test/cupertino/date_picker_test.dart +++ b/packages/flutter/test/cupertino/date_picker_test.dart @@ -2487,6 +2487,31 @@ void main() { expect(testWidth, equals(largestWidth)); expect(widths.indexOf(largestWidth), equals(1)); }, skip: isBrowser); // https://github.com/flutter/flutter/issues/39998 + + // Regression test for https://github.com/flutter/flutter/issues/161773 + testWidgets('CupertinoDatePicker date value baseline alignment', (WidgetTester tester) async { + await tester.pumpWidget( + CupertinoApp( + home: Center( + child: SizedBox( + width: 400, + height: 400, + child: CupertinoDatePicker( + mode: CupertinoDatePickerMode.date, + onDateTimeChanged: (_) {}, + initialDateTime: DateTime(2025, 2, 14), + ), + ), + ), + ), + ); + + Offset lastOffset = tester.getTopLeft(find.text('November')); + expect(tester.getTopLeft(find.text('11')).dy, lastOffset.dy); + + lastOffset = tester.getTopLeft(find.text('11')); + expect(tester.getTopLeft(find.text('2022')).dy, lastOffset.dy); + }); } Widget _buildPicker({