Skip to content

Commit

Permalink
reland #105109 (#105588)
Browse files Browse the repository at this point in the history
  • Loading branch information
guidezpl authored Jun 14, 2022
1 parent c857857 commit 1d53378
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions dev/tools/gen_defaults/lib/dialog_template.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class _TokenDefaultsM3 extends DialogTheme {
@override
TextStyle? get contentTextStyle => ${textStyle("md.comp.dialog.supporting-text")};
@override
EdgeInsetsGeometry? get actionsPadding => const EdgeInsets.only(left: 24.0, right: 24.0, bottom: 24.0);
}
''';
}
13 changes: 9 additions & 4 deletions packages/flutter/lib/src/material/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -555,11 +555,10 @@ class AlertDialog extends StatelessWidget {

if (actions != null) {
final double spacing = (buttonPadding?.horizontal ?? 16) / 2;
final EdgeInsetsGeometry effetiveActionsPadding = (actionsPadding ?? EdgeInsets.zero).add(
theme.useMaterial3 ? const EdgeInsets.only(left: 24.0, right: 24.0, bottom: 24.0) : EdgeInsets.all(spacing),
);
actionsWidget = Padding(
padding: effetiveActionsPadding,
padding: actionsPadding ?? dialogTheme.actionsPadding ?? (
theme.useMaterial3 ? defaults.actionsPadding! : defaults.actionsPadding!.add(EdgeInsets.all(spacing))
),
child: OverflowBar(
alignment: actionsAlignment ?? MainAxisAlignment.end,
spacing: spacing,
Expand Down Expand Up @@ -1205,6 +1204,9 @@ class _DefaultsM2 extends DialogTheme {

@override
TextStyle? get contentTextStyle => _textTheme.subtitle1;

@override
EdgeInsetsGeometry? get actionsPadding => EdgeInsets.zero;
}

// BEGIN GENERATED TOKEN PROPERTIES
Expand Down Expand Up @@ -1235,6 +1237,9 @@ class _TokenDefaultsM3 extends DialogTheme {

@override
TextStyle? get contentTextStyle => _textTheme.bodyMedium;

@override
EdgeInsetsGeometry? get actionsPadding => const EdgeInsets.only(left: 24.0, right: 24.0, bottom: 24.0);
}

// END GENERATED TOKEN PROPERTIES
11 changes: 10 additions & 1 deletion packages/flutter/lib/src/material/dialog_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class DialogTheme with Diagnosticable {
this.alignment,
this.titleTextStyle,
this.contentTextStyle,
this.actionsPadding,
});

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

/// Overrides the default value for [AlertDialog.actionsPadding].
final EdgeInsetsGeometry? actionsPadding;

/// Creates a copy of this object but with the given fields replaced with the
/// new values.
DialogTheme copyWith({
Expand All @@ -65,6 +69,7 @@ class DialogTheme with Diagnosticable {
AlignmentGeometry? alignment,
TextStyle? titleTextStyle,
TextStyle? contentTextStyle,
EdgeInsetsGeometry? actionsPadding,
}) {
return DialogTheme(
backgroundColor: backgroundColor ?? this.backgroundColor,
Expand All @@ -73,6 +78,7 @@ class DialogTheme with Diagnosticable {
alignment: alignment ?? this.alignment,
titleTextStyle: titleTextStyle ?? this.titleTextStyle,
contentTextStyle: contentTextStyle ?? this.contentTextStyle,
actionsPadding: actionsPadding ?? this.actionsPadding,
);
}

Expand All @@ -95,6 +101,7 @@ class DialogTheme with Diagnosticable {
alignment: AlignmentGeometry.lerp(a?.alignment, b?.alignment, t),
titleTextStyle: TextStyle.lerp(a?.titleTextStyle, b?.titleTextStyle, t),
contentTextStyle: TextStyle.lerp(a?.contentTextStyle, b?.contentTextStyle, t),
actionsPadding: EdgeInsetsGeometry.lerp(a?.actionsPadding, b?.actionsPadding, t),
);
}

Expand All @@ -115,7 +122,8 @@ class DialogTheme with Diagnosticable {
&& other.shape == shape
&& other.alignment == alignment
&& other.titleTextStyle == titleTextStyle
&& other.contentTextStyle == contentTextStyle;
&& other.contentTextStyle == contentTextStyle
&& other.actionsPadding == actionsPadding;
}

@override
Expand All @@ -127,5 +135,6 @@ class DialogTheme with Diagnosticable {
properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment, defaultValue: null));
properties.add(DiagnosticsProperty<TextStyle>('titleTextStyle', titleTextStyle, defaultValue: null));
properties.add(DiagnosticsProperty<TextStyle>('contentTextStyle', contentTextStyle, defaultValue: null));
properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('actionsPadding', actionsPadding, defaultValue: null));
}
}
2 changes: 2 additions & 0 deletions packages/flutter/test/material/dialog_theme_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void main() {
alignment: Alignment.bottomLeft,
titleTextStyle: TextStyle(color: Color(0xffffffff)),
contentTextStyle: TextStyle(color: Color(0xff000000)),
actionsPadding: EdgeInsets.all(8.0),
).debugFillProperties(builder);
final List<String> description = builder.properties
.where((DiagnosticsNode n) => !n.isFiltered(DiagnosticLevel.info))
Expand All @@ -64,6 +65,7 @@ void main() {
'alignment: Alignment.bottomLeft',
'titleTextStyle: TextStyle(inherit: true, color: Color(0xffffffff))',
'contentTextStyle: TextStyle(inherit: true, color: Color(0xff000000))',
'actionsPadding: EdgeInsets.all(8.0)',
]);
});

Expand Down

0 comments on commit 1d53378

Please sign in to comment.