Material Date Picker should honor DialogTheme shape, and elevation. (#53713)
* Date Picker should honor DialogTheme shape, and elevation.
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 dbafa1d..1d05ecf 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 '../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 @@
);
final Size dialogSize = _dialogSize(context) * textScaleFactor;
+ final DialogTheme dialogTheme = Theme.of(context).dialogTheme;
return Dialog(
child: AnimatedContainer(
width: dialogSize.width,
@@ -473,11 +475,13 @@
),
),
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 768f038..eba742f 100644
--- a/packages/flutter/test/material/date_picker_test.dart
+++ b/packages/flutter/test/material/date_picker_test.dart
@@ -247,6 +247,77 @@
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<Material>(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<Material>(find.descendant(of: find.byType(Dialog), matching: find.byType(Material)).first);
+ expect(themeDialogMaterial.shape, customDialogTheme.shape);
+ expect(themeDialogMaterial.elevation, customDialogTheme.elevation);
+ });
+
});
group('Calendar mode', () {