From f2acfbca82cd09300f8f2a3e5c17fd776f44a3aa Mon Sep 17 00:00:00 2001 From: Darren Austin Date: Wed, 1 Apr 2020 00:45:45 -0700 Subject: [PATCH] Material Date Picker should honor DialogTheme shape, and elevation. (#53713) * Date Picker should honor DialogTheme shape, and elevation. --- .../material/pickers/date_picker_dialog.dart | 8 ++- .../test/material/date_picker_test.dart | 71 +++++++++++++++++++ 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/material/pickers/date_picker_dialog.dart b/packages/flutter/lib/src/material/pickers/date_picker_dialog.dart index dbafa1d0b6..1d05ecf095 100644 --- a/packages/flutter/lib/src/material/pickers/date_picker_dialog.dart +++ b/packages/flutter/lib/src/material/pickers/date_picker_dialog.dart @@ -12,6 +12,7 @@ import '../button_theme.dart'; import '../color_scheme.dart'; import '../debug.dart'; import '../dialog.dart'; +import '../dialog_theme.dart'; import '../flat_button.dart'; import '../icons.dart'; import '../material_localizations.dart'; @@ -427,6 +428,7 @@ class _DatePickerDialogState extends State<_DatePickerDialog> { ); final Size dialogSize = _dialogSize(context) * textScaleFactor; + final DialogTheme dialogTheme = Theme.of(context).dialogTheme; return Dialog( child: AnimatedContainer( width: dialogSize.width, @@ -473,11 +475,13 @@ class _DatePickerDialogState extends State<_DatePickerDialog> { ), ), insetPadding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 24.0), - shape: const RoundedRectangleBorder( + // The default dialog shape is radius 2 rounded rect, but the spec has + // been updated to 4, so we will use that here for the Date Picker, but + // only if there isn't one provided in the theme. + shape: dialogTheme.shape ?? const RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(4.0)) ), clipBehavior: Clip.antiAlias, - elevation: 24.0, ); } } diff --git a/packages/flutter/test/material/date_picker_test.dart b/packages/flutter/test/material/date_picker_test.dart index 768f038793..eba742f484 100644 --- a/packages/flutter/test/material/date_picker_test.dart +++ b/packages/flutter/test/material/date_picker_test.dart @@ -247,6 +247,77 @@ void main() { expect(nestedObserver.datePickerCount, 1); }); + testWidgets('honors DialogTheme for shape and elevation', (WidgetTester tester) async { + // Test that the defaults work + const DialogTheme datePickerDefaultDialogTheme = DialogTheme( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(4.0)) + ), + elevation: 24, + ); + await tester.pumpWidget( + MaterialApp( + home: Center( + child: Builder( + builder: (BuildContext context) { + return RaisedButton( + child: const Text('X'), + onPressed: () { + showDatePicker( + context: context, + initialDate: DateTime.now(), + firstDate: DateTime(2018), + lastDate: DateTime(2030), + ); + }, + ); + }, + ), + ), + ), + ); + await tester.tap(find.text('X')); + await tester.pumpAndSettle(); + final Material defaultDialogMaterial = tester.widget(find.descendant(of: find.byType(Dialog), matching: find.byType(Material)).first); + expect(defaultDialogMaterial.shape, datePickerDefaultDialogTheme.shape); + expect(defaultDialogMaterial.elevation, datePickerDefaultDialogTheme.elevation); + + // Test that it honors ThemeData.dialogTheme settings + const DialogTheme customDialogTheme = DialogTheme( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(40.0)) + ), + elevation: 50, + ); + await tester.pumpWidget( + MaterialApp( + theme: ThemeData.fallback().copyWith(dialogTheme: customDialogTheme), + home: Center( + child: Builder( + builder: (BuildContext context) { + return RaisedButton( + child: const Text('X'), + onPressed: () { + showDatePicker( + context: context, + initialDate: DateTime.now(), + firstDate: DateTime(2018), + lastDate: DateTime(2030), + ); + }, + ); + }, + ), + ), + ), + ); + await tester.tap(find.text('X')); + await tester.pumpAndSettle(); + final Material themeDialogMaterial = tester.widget(find.descendant(of: find.byType(Dialog), matching: find.byType(Material)).first); + expect(themeDialogMaterial.shape, customDialogTheme.shape); + expect(themeDialogMaterial.elevation, customDialogTheme.elevation); + }); + }); group('Calendar mode', () {