Skip to content

Commit 5d10cf5

Browse files
authored
Add actionsPadding to dialog theme (#105109)
* add actionsPadding to dialog theme and refactor * fix typo * remove trailing spaces
1 parent 180b31d commit 5d10cf5

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

dev/tools/gen_defaults/lib/dialog_template.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class _TokenDefaultsM3 extends DialogTheme {
3434
3535
@override
3636
TextStyle? get contentTextStyle => ${textStyle("md.comp.dialog.supporting-text")};
37+
38+
@override
39+
EdgeInsetsGeometry? get actionsPadding => const EdgeInsets.only(left: 24.0, right: 24.0, bottom: 24.0);
3740
}
3841
''';
3942
}

packages/flutter/lib/src/material/dialog.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -554,11 +554,10 @@ class AlertDialog extends StatelessWidget {
554554

555555
if (actions != null) {
556556
final double spacing = (buttonPadding?.horizontal ?? 16) / 2;
557-
final EdgeInsetsGeometry effetiveActionsPadding = (actionsPadding ?? EdgeInsets.zero).add(
558-
theme.useMaterial3 ? const EdgeInsets.only(left: 24.0, right: 24.0, bottom: 24.0) : EdgeInsets.all(spacing),
559-
);
560557
actionsWidget = Padding(
561-
padding: effetiveActionsPadding,
558+
padding: actionsPadding ?? dialogTheme.actionsPadding ?? (
559+
theme.useMaterial3 ? defaults.actionsPadding! : defaults.actionsPadding!.add(EdgeInsets.all(spacing))
560+
),
562561
child: OverflowBar(
563562
alignment: actionsAlignment ?? MainAxisAlignment.end,
564563
spacing: spacing,
@@ -1203,6 +1202,9 @@ class _DefaultsM2 extends DialogTheme {
12031202

12041203
@override
12051204
TextStyle? get contentTextStyle => _textTheme.subtitle1;
1205+
1206+
@override
1207+
EdgeInsetsGeometry? get actionsPadding => EdgeInsets.zero;
12061208
}
12071209

12081210
// BEGIN GENERATED TOKEN PROPERTIES
@@ -1233,6 +1235,9 @@ class _TokenDefaultsM3 extends DialogTheme {
12331235

12341236
@override
12351237
TextStyle? get contentTextStyle => _textTheme.bodyMedium;
1238+
1239+
@override
1240+
EdgeInsetsGeometry? get actionsPadding => const EdgeInsets.only(left: 24.0, right: 24.0, bottom: 24.0);
12361241
}
12371242

12381243
// END GENERATED TOKEN PROPERTIES

packages/flutter/lib/src/material/dialog_theme.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class DialogTheme with Diagnosticable {
3434
this.alignment,
3535
this.titleTextStyle,
3636
this.contentTextStyle,
37+
this.actionsPadding,
3738
});
3839

3940
/// Overrides the default value for [Dialog.backgroundColor].
@@ -56,6 +57,9 @@ class DialogTheme with Diagnosticable {
5657
/// [AlertDialog.content].
5758
final TextStyle? contentTextStyle;
5859

60+
/// Overrides the default value for [AlertDialog.actionsPadding].
61+
final EdgeInsetsGeometry? actionsPadding;
62+
5963
/// Creates a copy of this object but with the given fields replaced with the
6064
/// new values.
6165
DialogTheme copyWith({
@@ -65,6 +69,7 @@ class DialogTheme with Diagnosticable {
6569
AlignmentGeometry? alignment,
6670
TextStyle? titleTextStyle,
6771
TextStyle? contentTextStyle,
72+
EdgeInsetsGeometry? actionsPadding,
6873
}) {
6974
return DialogTheme(
7075
backgroundColor: backgroundColor ?? this.backgroundColor,
@@ -73,6 +78,7 @@ class DialogTheme with Diagnosticable {
7378
alignment: alignment ?? this.alignment,
7479
titleTextStyle: titleTextStyle ?? this.titleTextStyle,
7580
contentTextStyle: contentTextStyle ?? this.contentTextStyle,
81+
actionsPadding: actionsPadding ?? this.actionsPadding,
7682
);
7783
}
7884

@@ -95,6 +101,7 @@ class DialogTheme with Diagnosticable {
95101
alignment: AlignmentGeometry.lerp(a?.alignment, b?.alignment, t),
96102
titleTextStyle: TextStyle.lerp(a?.titleTextStyle, b?.titleTextStyle, t),
97103
contentTextStyle: TextStyle.lerp(a?.contentTextStyle, b?.contentTextStyle, t),
104+
actionsPadding: EdgeInsetsGeometry.lerp(a?.actionsPadding, b?.actionsPadding, t),
98105
);
99106
}
100107

@@ -115,7 +122,8 @@ class DialogTheme with Diagnosticable {
115122
&& other.shape == shape
116123
&& other.alignment == alignment
117124
&& other.titleTextStyle == titleTextStyle
118-
&& other.contentTextStyle == contentTextStyle;
125+
&& other.contentTextStyle == contentTextStyle
126+
&& other.actionsPadding == actionsPadding;
119127
}
120128

121129
@override
@@ -127,5 +135,6 @@ class DialogTheme with Diagnosticable {
127135
properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment, defaultValue: null));
128136
properties.add(DiagnosticsProperty<TextStyle>('titleTextStyle', titleTextStyle, defaultValue: null));
129137
properties.add(DiagnosticsProperty<TextStyle>('contentTextStyle', contentTextStyle, defaultValue: null));
138+
properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('actionsPadding', actionsPadding, defaultValue: null));
130139
}
131140
}

packages/flutter/test/material/dialog_theme_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ void main() {
5454
alignment: Alignment.bottomLeft,
5555
titleTextStyle: TextStyle(color: Color(0xffffffff)),
5656
contentTextStyle: TextStyle(color: Color(0xff000000)),
57+
actionsPadding: EdgeInsets.all(8.0),
5758
).debugFillProperties(builder);
5859
final List<String> description = builder.properties
5960
.where((DiagnosticsNode n) => !n.isFiltered(DiagnosticLevel.info))
@@ -64,6 +65,7 @@ void main() {
6465
'alignment: Alignment.bottomLeft',
6566
'titleTextStyle: TextStyle(inherit: true, color: Color(0xffffffff))',
6667
'contentTextStyle: TextStyle(inherit: true, color: Color(0xff000000))',
68+
'actionsPadding: EdgeInsets.all(8.0)',
6769
]);
6870
});
6971

0 commit comments

Comments
 (0)