Unverified Commit f0bb9d57 authored by David Martos's avatar David Martos Committed by GitHub

barrierColor property in DialogTheme (#142490)

parent 8b228b9e
...@@ -1327,7 +1327,8 @@ Widget _buildMaterialDialogTransitions(BuildContext context, Animation<double> a ...@@ -1327,7 +1327,8 @@ Widget _buildMaterialDialogTransitions(BuildContext context, Animation<double> a
/// barrier will dismiss the dialog. It is `true` by default and can not be `null`. /// barrier will dismiss the dialog. It is `true` by default and can not be `null`.
/// ///
/// The `barrierColor` argument is used to specify the color of the modal /// The `barrierColor` argument is used to specify the color of the modal
/// barrier that darkens everything below the dialog. If `null` the default color /// barrier that darkens everything below the dialog. If `null` the `barrierColor`
/// field from `DialogTheme` is used. If that is `null` the default color
/// `Colors.black54` is used. /// `Colors.black54` is used.
/// ///
/// The `useSafeArea` argument is used to indicate if the dialog should only /// The `useSafeArea` argument is used to indicate if the dialog should only
...@@ -1428,7 +1429,7 @@ Future<T?> showDialog<T>({ ...@@ -1428,7 +1429,7 @@ Future<T?> showDialog<T>({
return Navigator.of(context, rootNavigator: useRootNavigator).push<T>(DialogRoute<T>( return Navigator.of(context, rootNavigator: useRootNavigator).push<T>(DialogRoute<T>(
context: context, context: context,
builder: builder, builder: builder,
barrierColor: barrierColor ?? Colors.black54, barrierColor: barrierColor ?? Theme.of(context).dialogTheme.barrierColor ?? Colors.black54,
barrierDismissible: barrierDismissible, barrierDismissible: barrierDismissible,
barrierLabel: barrierLabel, barrierLabel: barrierLabel,
useSafeArea: useSafeArea, useSafeArea: useSafeArea,
......
...@@ -38,6 +38,7 @@ class DialogTheme with Diagnosticable { ...@@ -38,6 +38,7 @@ class DialogTheme with Diagnosticable {
this.titleTextStyle, this.titleTextStyle,
this.contentTextStyle, this.contentTextStyle,
this.actionsPadding, this.actionsPadding,
this.barrierColor,
}); });
/// Overrides the default value for [Dialog.backgroundColor]. /// Overrides the default value for [Dialog.backgroundColor].
...@@ -72,6 +73,9 @@ class DialogTheme with Diagnosticable { ...@@ -72,6 +73,9 @@ class DialogTheme with Diagnosticable {
/// Used to configure the [IconTheme] for the [AlertDialog.icon] widget. /// Used to configure the [IconTheme] for the [AlertDialog.icon] widget.
final Color? iconColor; final Color? iconColor;
/// Overrides the default value for [barrierColor] in [showDialog].
final Color? barrierColor;
/// Creates a copy of this object but with the given fields replaced with the /// Creates a copy of this object but with the given fields replaced with the
/// new values. /// new values.
DialogTheme copyWith({ DialogTheme copyWith({
...@@ -85,6 +89,7 @@ class DialogTheme with Diagnosticable { ...@@ -85,6 +89,7 @@ class DialogTheme with Diagnosticable {
TextStyle? titleTextStyle, TextStyle? titleTextStyle,
TextStyle? contentTextStyle, TextStyle? contentTextStyle,
EdgeInsetsGeometry? actionsPadding, EdgeInsetsGeometry? actionsPadding,
Color? barrierColor,
}) { }) {
return DialogTheme( return DialogTheme(
backgroundColor: backgroundColor ?? this.backgroundColor, backgroundColor: backgroundColor ?? this.backgroundColor,
...@@ -97,6 +102,7 @@ class DialogTheme with Diagnosticable { ...@@ -97,6 +102,7 @@ class DialogTheme with Diagnosticable {
titleTextStyle: titleTextStyle ?? this.titleTextStyle, titleTextStyle: titleTextStyle ?? this.titleTextStyle,
contentTextStyle: contentTextStyle ?? this.contentTextStyle, contentTextStyle: contentTextStyle ?? this.contentTextStyle,
actionsPadding: actionsPadding ?? this.actionsPadding, actionsPadding: actionsPadding ?? this.actionsPadding,
barrierColor: barrierColor ?? this.barrierColor,
); );
} }
...@@ -123,6 +129,7 @@ class DialogTheme with Diagnosticable { ...@@ -123,6 +129,7 @@ class DialogTheme with Diagnosticable {
titleTextStyle: TextStyle.lerp(a?.titleTextStyle, b?.titleTextStyle, t), titleTextStyle: TextStyle.lerp(a?.titleTextStyle, b?.titleTextStyle, t),
contentTextStyle: TextStyle.lerp(a?.contentTextStyle, b?.contentTextStyle, t), contentTextStyle: TextStyle.lerp(a?.contentTextStyle, b?.contentTextStyle, t),
actionsPadding: EdgeInsetsGeometry.lerp(a?.actionsPadding, b?.actionsPadding, t), actionsPadding: EdgeInsetsGeometry.lerp(a?.actionsPadding, b?.actionsPadding, t),
barrierColor: Color.lerp(a?.barrierColor, b?.barrierColor, t),
); );
} }
...@@ -147,7 +154,8 @@ class DialogTheme with Diagnosticable { ...@@ -147,7 +154,8 @@ class DialogTheme with Diagnosticable {
&& other.iconColor == iconColor && other.iconColor == iconColor
&& other.titleTextStyle == titleTextStyle && other.titleTextStyle == titleTextStyle
&& other.contentTextStyle == contentTextStyle && other.contentTextStyle == contentTextStyle
&& other.actionsPadding == actionsPadding; && other.actionsPadding == actionsPadding
&& other.barrierColor == barrierColor;
} }
@override @override
...@@ -163,5 +171,6 @@ class DialogTheme with Diagnosticable { ...@@ -163,5 +171,6 @@ class DialogTheme with Diagnosticable {
properties.add(DiagnosticsProperty<TextStyle>('titleTextStyle', titleTextStyle, defaultValue: null)); properties.add(DiagnosticsProperty<TextStyle>('titleTextStyle', titleTextStyle, defaultValue: null));
properties.add(DiagnosticsProperty<TextStyle>('contentTextStyle', contentTextStyle, defaultValue: null)); properties.add(DiagnosticsProperty<TextStyle>('contentTextStyle', contentTextStyle, defaultValue: null));
properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('actionsPadding', actionsPadding, defaultValue: null)); properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('actionsPadding', actionsPadding, defaultValue: null));
properties.add(ColorProperty('barrierColor', barrierColor));
} }
} }
...@@ -66,6 +66,7 @@ void main() { ...@@ -66,6 +66,7 @@ void main() {
titleTextStyle: TextStyle(color: Color(0xffffffff)), titleTextStyle: TextStyle(color: Color(0xffffffff)),
contentTextStyle: TextStyle(color: Color(0xff000000)), contentTextStyle: TextStyle(color: Color(0xff000000)),
actionsPadding: EdgeInsets.all(8.0), actionsPadding: EdgeInsets.all(8.0),
barrierColor: Color(0xff000005),
).debugFillProperties(builder); ).debugFillProperties(builder);
final List<String> description = builder.properties final List<String> description = builder.properties
.where((DiagnosticsNode n) => !n.isFiltered(DiagnosticLevel.info)) .where((DiagnosticsNode n) => !n.isFiltered(DiagnosticLevel.info))
...@@ -80,6 +81,7 @@ void main() { ...@@ -80,6 +81,7 @@ void main() {
'titleTextStyle: TextStyle(inherit: true, color: Color(0xffffffff))', 'titleTextStyle: TextStyle(inherit: true, color: Color(0xffffffff))',
'contentTextStyle: TextStyle(inherit: true, color: Color(0xff000000))', 'contentTextStyle: TextStyle(inherit: true, color: Color(0xff000000))',
'actionsPadding: EdgeInsets.all(8.0)', 'actionsPadding: EdgeInsets.all(8.0)',
'barrierColor: Color(0xff000005)',
]); ]);
}); });
...@@ -499,4 +501,17 @@ void main() { ...@@ -499,4 +501,17 @@ void main() {
final RenderParagraph content = _getTextRenderObject(tester, contentText); final RenderParagraph content = _getTextRenderObject(tester, contentText);
expect(content.text.style!.color, contentTextStyle.color); expect(content.text.style!.color, contentTextStyle.color);
}); });
testWidgets('Custom barrierColor - Theme', (WidgetTester tester) async {
const Color barrierColor = Colors.blue;
const SimpleDialog dialog = SimpleDialog();
final ThemeData theme = ThemeData(dialogTheme: const DialogTheme(barrierColor: barrierColor));
await tester.pumpWidget(_appWithDialog(tester, dialog, theme: theme));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
final ModalBarrier modalBarrier = tester.widget(find.byType(ModalBarrier).last);
expect(modalBarrier.color, barrierColor);
});
} }
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