Fix insetPadding
parameter nullability for dialogs (#143305)
fixes [`insetPadding` should be nullable in dialogs](https://github.com/flutter/flutter/issues/117125)
This commit is contained in:
parent
0650b76884
commit
d271791e8c
@ -54,7 +54,7 @@ class Dialog extends StatelessWidget {
|
|||||||
this.surfaceTintColor,
|
this.surfaceTintColor,
|
||||||
this.insetAnimationDuration = const Duration(milliseconds: 100),
|
this.insetAnimationDuration = const Duration(milliseconds: 100),
|
||||||
this.insetAnimationCurve = Curves.decelerate,
|
this.insetAnimationCurve = Curves.decelerate,
|
||||||
this.insetPadding = _defaultInsetPadding,
|
this.insetPadding,
|
||||||
this.clipBehavior = Clip.none,
|
this.clipBehavior = Clip.none,
|
||||||
this.shape,
|
this.shape,
|
||||||
this.alignment,
|
this.alignment,
|
||||||
@ -215,7 +215,8 @@ class Dialog extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final ThemeData theme = Theme.of(context);
|
final ThemeData theme = Theme.of(context);
|
||||||
final DialogTheme dialogTheme = DialogTheme.of(context);
|
final DialogTheme dialogTheme = DialogTheme.of(context);
|
||||||
final EdgeInsets effectivePadding = MediaQuery.viewInsetsOf(context) + (insetPadding ?? EdgeInsets.zero);
|
final EdgeInsets effectivePadding = MediaQuery.viewInsetsOf(context)
|
||||||
|
+ (insetPadding ?? dialogTheme.insetPadding ?? _defaultInsetPadding);
|
||||||
final DialogTheme defaults = theme.useMaterial3
|
final DialogTheme defaults = theme.useMaterial3
|
||||||
? (_fullscreen ? _DialogFullscreenDefaultsM3(context) : _DialogDefaultsM3(context))
|
? (_fullscreen ? _DialogFullscreenDefaultsM3(context) : _DialogDefaultsM3(context))
|
||||||
: _DialogDefaultsM2(context);
|
: _DialogDefaultsM2(context);
|
||||||
@ -387,7 +388,7 @@ class AlertDialog extends StatelessWidget {
|
|||||||
this.shadowColor,
|
this.shadowColor,
|
||||||
this.surfaceTintColor,
|
this.surfaceTintColor,
|
||||||
this.semanticLabel,
|
this.semanticLabel,
|
||||||
this.insetPadding = _defaultInsetPadding,
|
this.insetPadding,
|
||||||
this.clipBehavior = Clip.none,
|
this.clipBehavior = Clip.none,
|
||||||
this.shape,
|
this.shape,
|
||||||
this.alignment,
|
this.alignment,
|
||||||
@ -676,7 +677,7 @@ class AlertDialog extends StatelessWidget {
|
|||||||
final String? semanticLabel;
|
final String? semanticLabel;
|
||||||
|
|
||||||
/// {@macro flutter.material.dialog.insetPadding}
|
/// {@macro flutter.material.dialog.insetPadding}
|
||||||
final EdgeInsets insetPadding;
|
final EdgeInsets? insetPadding;
|
||||||
|
|
||||||
/// {@macro flutter.material.dialog.clipBehavior}
|
/// {@macro flutter.material.dialog.clipBehavior}
|
||||||
final Clip clipBehavior;
|
final Clip clipBehavior;
|
||||||
@ -912,7 +913,7 @@ class _AdaptiveAlertDialog extends AlertDialog {
|
|||||||
super.shadowColor,
|
super.shadowColor,
|
||||||
super.surfaceTintColor,
|
super.surfaceTintColor,
|
||||||
super.semanticLabel,
|
super.semanticLabel,
|
||||||
super.insetPadding = _defaultInsetPadding,
|
super.insetPadding,
|
||||||
super.clipBehavior = Clip.none,
|
super.clipBehavior = Clip.none,
|
||||||
super.shape,
|
super.shape,
|
||||||
super.alignment,
|
super.alignment,
|
||||||
@ -1110,7 +1111,7 @@ class SimpleDialog extends StatelessWidget {
|
|||||||
this.shadowColor,
|
this.shadowColor,
|
||||||
this.surfaceTintColor,
|
this.surfaceTintColor,
|
||||||
this.semanticLabel,
|
this.semanticLabel,
|
||||||
this.insetPadding = _defaultInsetPadding,
|
this.insetPadding,
|
||||||
this.clipBehavior = Clip.none,
|
this.clipBehavior = Clip.none,
|
||||||
this.shape,
|
this.shape,
|
||||||
this.alignment,
|
this.alignment,
|
||||||
@ -1185,7 +1186,7 @@ class SimpleDialog extends StatelessWidget {
|
|||||||
final String? semanticLabel;
|
final String? semanticLabel;
|
||||||
|
|
||||||
/// {@macro flutter.material.dialog.insetPadding}
|
/// {@macro flutter.material.dialog.insetPadding}
|
||||||
final EdgeInsets insetPadding;
|
final EdgeInsets? insetPadding;
|
||||||
|
|
||||||
/// {@macro flutter.material.dialog.clipBehavior}
|
/// {@macro flutter.material.dialog.clipBehavior}
|
||||||
final Clip clipBehavior;
|
final Clip clipBehavior;
|
||||||
|
@ -39,6 +39,7 @@ class DialogTheme with Diagnosticable {
|
|||||||
this.contentTextStyle,
|
this.contentTextStyle,
|
||||||
this.actionsPadding,
|
this.actionsPadding,
|
||||||
this.barrierColor,
|
this.barrierColor,
|
||||||
|
this.insetPadding,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Overrides the default value for [Dialog.backgroundColor].
|
/// Overrides the default value for [Dialog.backgroundColor].
|
||||||
@ -76,6 +77,9 @@ class DialogTheme with Diagnosticable {
|
|||||||
/// Overrides the default value for [barrierColor] in [showDialog].
|
/// Overrides the default value for [barrierColor] in [showDialog].
|
||||||
final Color? barrierColor;
|
final Color? barrierColor;
|
||||||
|
|
||||||
|
/// Overrides the default value for [Dialog.insetPadding].
|
||||||
|
final EdgeInsets? insetPadding;
|
||||||
|
|
||||||
/// 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({
|
||||||
@ -90,6 +94,7 @@ class DialogTheme with Diagnosticable {
|
|||||||
TextStyle? contentTextStyle,
|
TextStyle? contentTextStyle,
|
||||||
EdgeInsetsGeometry? actionsPadding,
|
EdgeInsetsGeometry? actionsPadding,
|
||||||
Color? barrierColor,
|
Color? barrierColor,
|
||||||
|
EdgeInsets? insetPadding,
|
||||||
}) {
|
}) {
|
||||||
return DialogTheme(
|
return DialogTheme(
|
||||||
backgroundColor: backgroundColor ?? this.backgroundColor,
|
backgroundColor: backgroundColor ?? this.backgroundColor,
|
||||||
@ -103,6 +108,7 @@ class DialogTheme with Diagnosticable {
|
|||||||
contentTextStyle: contentTextStyle ?? this.contentTextStyle,
|
contentTextStyle: contentTextStyle ?? this.contentTextStyle,
|
||||||
actionsPadding: actionsPadding ?? this.actionsPadding,
|
actionsPadding: actionsPadding ?? this.actionsPadding,
|
||||||
barrierColor: barrierColor ?? this.barrierColor,
|
barrierColor: barrierColor ?? this.barrierColor,
|
||||||
|
insetPadding: insetPadding ?? this.insetPadding,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,11 +136,25 @@ class DialogTheme with Diagnosticable {
|
|||||||
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),
|
barrierColor: Color.lerp(a?.barrierColor, b?.barrierColor, t),
|
||||||
|
insetPadding: EdgeInsets.lerp(a?.insetPadding, b?.insetPadding, t),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get hashCode => shape.hashCode;
|
int get hashCode => Object.hashAll(<Object?>[
|
||||||
|
backgroundColor,
|
||||||
|
elevation,
|
||||||
|
shadowColor,
|
||||||
|
surfaceTintColor,
|
||||||
|
shape,
|
||||||
|
alignment,
|
||||||
|
iconColor,
|
||||||
|
titleTextStyle,
|
||||||
|
contentTextStyle,
|
||||||
|
actionsPadding,
|
||||||
|
barrierColor,
|
||||||
|
insetPadding,
|
||||||
|
]);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) {
|
bool operator ==(Object other) {
|
||||||
@ -155,7 +175,8 @@ class DialogTheme with Diagnosticable {
|
|||||||
&& other.titleTextStyle == titleTextStyle
|
&& other.titleTextStyle == titleTextStyle
|
||||||
&& other.contentTextStyle == contentTextStyle
|
&& other.contentTextStyle == contentTextStyle
|
||||||
&& other.actionsPadding == actionsPadding
|
&& other.actionsPadding == actionsPadding
|
||||||
&& other.barrierColor == barrierColor;
|
&& other.barrierColor == barrierColor
|
||||||
|
&& other.insetPadding == insetPadding;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -172,5 +193,6 @@ class DialogTheme with Diagnosticable {
|
|||||||
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));
|
properties.add(ColorProperty('barrierColor', barrierColor));
|
||||||
|
properties.add(DiagnosticsProperty<EdgeInsets>('insetPadding', insetPadding, defaultValue: null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1656,12 +1656,12 @@ void main() {
|
|||||||
// The default testing screen (800, 600)
|
// The default testing screen (800, 600)
|
||||||
const Rect screenRect = Rect.fromLTRB(0.0, 0.0, 800.0, 600.0);
|
const Rect screenRect = Rect.fromLTRB(0.0, 0.0, 800.0, 600.0);
|
||||||
|
|
||||||
// Test with no padding
|
// Test with no padding.
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
const MediaQuery(
|
const MediaQuery(
|
||||||
data: MediaQueryData(),
|
data: MediaQueryData(),
|
||||||
child: Dialog(
|
child: Dialog(
|
||||||
insetPadding: null,
|
insetPadding: EdgeInsets.zero,
|
||||||
child: Placeholder(),
|
child: Placeholder(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -1669,7 +1669,7 @@ void main() {
|
|||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(tester.getRect(find.byType(Placeholder)), screenRect);
|
expect(tester.getRect(find.byType(Placeholder)), screenRect);
|
||||||
|
|
||||||
// Test with an insetPadding
|
// Test with an insetPadding.
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
const MediaQuery(
|
const MediaQuery(
|
||||||
data: MediaQueryData(),
|
data: MediaQueryData(),
|
||||||
@ -2841,6 +2841,21 @@ void main() {
|
|||||||
expect(okNode.hasFocus, false);
|
expect(okNode.hasFocus, false);
|
||||||
expect(cancelNode.hasFocus, false);
|
expect(cancelNode.hasFocus, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('Dialog.insetPadding is nullable', (WidgetTester tester) async {
|
||||||
|
const Dialog dialog = Dialog();
|
||||||
|
expect(dialog.insetPadding, isNull);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('AlertDialog.insetPadding is nullable', (WidgetTester tester) async {
|
||||||
|
const AlertDialog alertDialog = AlertDialog();
|
||||||
|
expect(alertDialog.insetPadding, isNull);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('SimpleDialog.insetPadding is nullable', (WidgetTester tester) async {
|
||||||
|
const SimpleDialog simpleDialog = SimpleDialog();
|
||||||
|
expect(simpleDialog.insetPadding, isNull);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class _RestorableDialogTestWidget extends StatelessWidget {
|
class _RestorableDialogTestWidget extends StatelessWidget {
|
||||||
|
@ -48,6 +48,11 @@ RenderParagraph _getTextRenderObject(WidgetTester tester, String text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
test('DialogTheme copyWith, ==, hashCode basics', () {
|
||||||
|
expect(const DialogTheme(), const DialogTheme().copyWith());
|
||||||
|
expect(const DialogTheme().hashCode, const DialogTheme().copyWith().hashCode);
|
||||||
|
});
|
||||||
|
|
||||||
test('DialogTheme lerp special cases', () {
|
test('DialogTheme lerp special cases', () {
|
||||||
expect(DialogTheme.lerp(null, null, 0), const DialogTheme());
|
expect(DialogTheme.lerp(null, null, 0), const DialogTheme());
|
||||||
const DialogTheme theme = DialogTheme();
|
const DialogTheme theme = DialogTheme();
|
||||||
@ -67,6 +72,7 @@ void main() {
|
|||||||
contentTextStyle: TextStyle(color: Color(0xff000000)),
|
contentTextStyle: TextStyle(color: Color(0xff000000)),
|
||||||
actionsPadding: EdgeInsets.all(8.0),
|
actionsPadding: EdgeInsets.all(8.0),
|
||||||
barrierColor: Color(0xff000005),
|
barrierColor: Color(0xff000005),
|
||||||
|
insetPadding: EdgeInsets.all(20.0),
|
||||||
).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))
|
||||||
@ -82,6 +88,7 @@ void main() {
|
|||||||
'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)',
|
'barrierColor: Color(0xff000005)',
|
||||||
|
'insetPadding: EdgeInsets.all(20.0)',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -514,4 +521,31 @@ void main() {
|
|||||||
final ModalBarrier modalBarrier = tester.widget(find.byType(ModalBarrier).last);
|
final ModalBarrier modalBarrier = tester.widget(find.byType(ModalBarrier).last);
|
||||||
expect(modalBarrier.color, barrierColor);
|
expect(modalBarrier.color, barrierColor);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('DialogTheme.insetPadding updates Dialog insetPadding', (WidgetTester tester) async {
|
||||||
|
// The default testing screen (800, 600)
|
||||||
|
const Rect screenRect = Rect.fromLTRB(0.0, 0.0, 800.0, 600.0);
|
||||||
|
const DialogTheme dialogTheme = DialogTheme(
|
||||||
|
insetPadding: EdgeInsets.fromLTRB(10, 15, 20, 25)
|
||||||
|
);
|
||||||
|
const Dialog dialog = Dialog(child: Placeholder());
|
||||||
|
|
||||||
|
await tester.pumpWidget(_appWithDialog(
|
||||||
|
tester,
|
||||||
|
dialog,
|
||||||
|
theme: ThemeData(dialogTheme: dialogTheme),
|
||||||
|
));
|
||||||
|
await tester.tap(find.text('X'));
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
tester.getRect(find.byType(Placeholder)),
|
||||||
|
Rect.fromLTRB(
|
||||||
|
screenRect.left + dialogTheme.insetPadding!.left,
|
||||||
|
screenRect.top + dialogTheme.insetPadding!.top,
|
||||||
|
screenRect.right - dialogTheme.insetPadding!.right,
|
||||||
|
screenRect.bottom - dialogTheme.insetPadding!.bottom,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user