Unverified Commit 2f95a5a3 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Fix `DatePicker` Dialog content not visible on lower text scale (#139236)

fixes [`DatePicker` dialog contents are hidden when using smaller text size](https://github.com/flutter/flutter/issues/139120)

### Description
- Fixed `DatePicker` dialog contents are hidden when using smaller text size.
- Add golden tests

### Golden Test (Before)

| `TextScale - 0.88` | `TextScale - 1.0` | `TextScale - 2.0` | 
| --------------- |  --------------- |  --------------- | 
|   <img src="https://github.com/flutter/flutter/assets/48603081/9f301c5d-3acd-4a9f-8fb7-aa7b2e9553a2"> |  <img src="https://github.com/flutter/flutter/assets/48603081/0496cf1a-5086-4cb1-ad3f-256f34346920"> | <img src="https://github.com/flutter/flutter/assets/48603081/2d1e1892-435a-4938-a7fc-2ffa4684828b"> | 

### Golden Test (After)

| `TextScale - 0.88` | `TextScale - 1.0` | `TextScale - 2.0` | 
| --------------- |  --------------- |  --------------- | 
|   <img src="https://github.com/flutter/flutter/assets/48603081/8fb922b7-0f2c-4f08-a091-b359a01e3600"> |  <img src="https://github.com/flutter/flutter/assets/48603081/59933cbf-49ef-46fb-98b5-217db2cc0ee7"> | <img src="https://github.com/flutter/flutter/assets/48603081/fd2501cb-511c-4b57-a4eb-f583af60aed7"> |
parent 92c2cadc
......@@ -687,7 +687,7 @@ class _DatePickerDialogState extends State<DatePickerDialog> with RestorationMix
final Size portraitDialogSize = useMaterial3 ? _inputPortraitDialogSizeM3 : _inputPortraitDialogSizeM2;
// Make sure the portrait dialog can fit the contents comfortably when
// resized from the landscape dialog.
final bool isFullyPortrait = constraints.maxHeight >= portraitDialogSize.height;
final bool isFullyPortrait = constraints.maxHeight >= math.min(dialogSize.height, portraitDialogSize.height);
switch (orientation) {
case Orientation.portrait:
......@@ -2874,6 +2874,8 @@ class _InputDateRangePickerDialog extends StatelessWidget {
),
);
final double textScaleFactor = MediaQuery.textScalerOf(context).clamp(maxScaleFactor: _kMaxTextScaleFactor).textScaleFactor;
final Size dialogSize = (useMaterial3 ? _inputPortraitDialogSizeM3 : _inputPortraitDialogSizeM2) * textScaleFactor;
switch (orientation) {
case Orientation.portrait:
return LayoutBuilder(
......@@ -2881,7 +2883,7 @@ class _InputDateRangePickerDialog extends StatelessWidget {
final Size portraitDialogSize = useMaterial3 ? _inputPortraitDialogSizeM3 : _inputPortraitDialogSizeM2;
// Make sure the portrait dialog can fit the contents comfortably when
// resized from the landscape dialog.
final bool isFullyPortrait = constraints.maxHeight >= portraitDialogSize.height;
final bool isFullyPortrait = constraints.maxHeight >= math.min(dialogSize.height, portraitDialogSize.height);
return Column(
mainAxisSize: MainAxisSize.min,
......
......@@ -2,6 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file is run as part of a reduced test set in CI on Mac and Windows
// machines.
@Tags(<String>['reduced-test-set'])
library;
import 'dart:ui';
import 'package:flutter/foundation.dart';
......@@ -69,20 +74,24 @@ void main() {
TextDirection textDirection = TextDirection.ltr,
bool useMaterial3 = false,
ThemeData? theme,
TextScaler textScaler = TextScaler.noScaling,
}) async {
late BuildContext buttonContext;
await tester.pumpWidget(MaterialApp(
theme: theme ?? ThemeData(useMaterial3: useMaterial3),
home: Material(
child: Builder(
builder: (BuildContext context) {
return ElevatedButton(
onPressed: () {
buttonContext = context;
},
child: const Text('Go'),
);
},
home: MediaQuery(
data: MediaQueryData(textScaler: textScaler),
child: Material(
child: Builder(
builder: (BuildContext context) {
return ElevatedButton(
onPressed: () {
buttonContext = context;
},
child: const Text('Go'),
);
},
),
),
),
));
......@@ -1472,7 +1481,7 @@ void main() {
});
// This is a regression test for https://github.com/flutter/flutter/issues/131989.
testWidgetsWithLeakTracking('Dialog contents do not overflow when resized from landscape to portrait',
testWidgetsWithLeakTracking('Dialog contents do not overflow when resized during orientation change',
(WidgetTester tester) async {
addTearDown(tester.view.reset);
// Initial window size is wide for landscape mode.
......@@ -1486,6 +1495,36 @@ void main() {
expect(tester.takeException(), null);
});
});
// This is a regression test for https://github.com/flutter/flutter/issues/139120.
testWidgetsWithLeakTracking('Dialog contents are visible - textScaler 0.88, 1.0, 2.0',
(WidgetTester tester) async {
addTearDown(tester.view.reset);
tester.view.physicalSize = const Size(400, 800);
tester.view.devicePixelRatio = 1.0;
final List<double> scales = <double>[0.88, 1.0, 2.0];
for (final double scale in scales) {
await tester.pumpWidget(
MaterialApp(
home: MediaQuery(
data: MediaQueryData(textScaler: TextScaler.linear(scale)),
child: Material(
child: DatePickerDialog(
firstDate: DateTime(2001),
lastDate: DateTime(2031, DateTime.december, 31),
initialDate: DateTime(2016, DateTime.january, 15),
initialEntryMode: DatePickerEntryMode.input,
),
),
),
),
);
await tester.pumpAndSettle();
await expectLater(find.byType(Dialog), matchesGoldenFile('date_picker.dialog.contents.visible.$scale.png'));
}
});
});
group('Semantics', () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment