diff --git a/packages/flutter/lib/src/material/date_picker.dart b/packages/flutter/lib/src/material/date_picker.dart index bc28ca39796..4eace111935 100644 --- a/packages/flutter/lib/src/material/date_picker.dart +++ b/packages/flutter/lib/src/material/date_picker.dart @@ -777,13 +777,21 @@ class _DatePickerDialogState extends State with RestorationMix switch (orientation) { case Orientation.portrait: + final bool isInputMode = + _entryMode.value == DatePickerEntryMode.inputOnly || + _entryMode.value == DatePickerEntryMode.input; + // When the portrait dialog does not fit vertically, hide the header when the entry mode + // is input, or hide the picker when the entry mode is not input. + final bool showHeader = isFullyPortrait || !isInputMode; + final bool showPicker = isFullyPortrait || isInputMode; + return Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - header, + if (showHeader) header, if (useMaterial3) Divider(height: 0, color: datePickerTheme.dividerColor), - if (isFullyPortrait) ...[Expanded(child: picker), actions], + if (showPicker) ...[Expanded(child: picker), actions], ], ); case Orientation.landscape: @@ -3175,10 +3183,8 @@ class _InputDateRangePickerDialog extends StatelessWidget { return Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - header, - if (isFullyPortrait) ...[Expanded(child: picker), actions], - ], + // When the portrait dialog does not fit vertically, hide the header. + children: [if (isFullyPortrait) header, Expanded(child: picker), actions], ); }, ); diff --git a/packages/flutter/test/material/date_picker_test.dart b/packages/flutter/test/material/date_picker_test.dart index f500a132ea5..f712364b53b 100644 --- a/packages/flutter/test/material/date_picker_test.dart +++ b/packages/flutter/test/material/date_picker_test.dart @@ -1662,6 +1662,31 @@ void main() { }); }); + // Regression test for https://github.com/flutter/flutter/issues/140311. + testWidgets('Text field stays visible when orientation is portrait and height is reduced', ( + WidgetTester tester, + ) async { + addTearDown(tester.view.reset); + tester.view.physicalSize = const Size(720, 1280); + tester.view.devicePixelRatio = 1.0; + initialEntryMode = DatePickerEntryMode.input; + + // Text field and header are visible by default. + await prepareDatePicker(tester, useMaterial3: true, (Future range) async { + expect(find.byType(TextField), findsOneWidget); + expect(find.text('Select date'), findsOne); + }); + + // Simulate the portait mode on a device with a small display when the virtual + // keyboard is visible. + tester.view.viewInsets = const FakeViewPadding(bottom: 1000); + await tester.pumpAndSettle(); + + // Text field is visible and header is hidden. + expect(find.byType(TextField), findsOneWidget); + expect(find.text('Select date'), findsNothing); + }); + // This is a regression test for https://github.com/flutter/flutter/issues/139120. testWidgets('Dialog contents are visible - textScaler 0.88, 1.0, 2.0', ( WidgetTester tester, diff --git a/packages/flutter/test/material/date_range_picker_test.dart b/packages/flutter/test/material/date_range_picker_test.dart index 46139146144..92371173479 100644 --- a/packages/flutter/test/material/date_range_picker_test.dart +++ b/packages/flutter/test/material/date_range_picker_test.dart @@ -1243,6 +1243,31 @@ void main() { expect(tester.takeException(), null); }); }); + + // Regression test for https://github.com/flutter/flutter/issues/140311. + testWidgets('Text field stays visible when orientation is portrait and height is reduced', ( + WidgetTester tester, + ) async { + addTearDown(tester.view.reset); + tester.view.physicalSize = const Size(720, 1280); + tester.view.devicePixelRatio = 1.0; + initialEntryMode = DatePickerEntryMode.input; + + // Text fields and header are visible by default. + await preparePicker(tester, useMaterial3: true, (Future range) async { + expect(find.byType(TextField), findsNWidgets(2)); + expect(find.text('Select range'), findsOne); + }); + + // Simulate the portait mode on a device with a small display when the virtual + // keyboard is visible. + tester.view.viewInsets = const FakeViewPadding(bottom: 1000); + await tester.pumpAndSettle(); + + // Text fields are visible and header is hidden + expect(find.byType(TextField), findsNWidgets(2)); + expect(find.text('Select range'), findsNothing); + }); }); testWidgets('DatePickerDialog is state restorable', (WidgetTester tester) async {