Unverified Commit 51b2c488 authored by Pierre-Louis's avatar Pierre-Louis Committed by GitHub

Fix actions padding for M3 alert dialogs (#105008)

* update docs

* use correct actions padding for dialogs

* remove trailing spaces

* Update dialog_theme.dart

* Update packages/flutter/lib/src/material/dialog.dart
Co-authored-by: 's avatarTaha Tesser <tessertaha@gmail.com>
Co-authored-by: 's avatarTaha Tesser <tessertaha@gmail.com>
parent 3d62732d
......@@ -268,7 +268,7 @@ class AlertDialog extends StatelessWidget {
this.contentPadding = const EdgeInsets.fromLTRB(24.0, 20.0, 24.0, 24.0),
this.contentTextStyle,
this.actions,
this.actionsPadding = EdgeInsets.zero,
this.actionsPadding,
this.actionsAlignment,
this.actionsOverflowAlignment,
this.actionsOverflowDirection,
......@@ -350,10 +350,9 @@ class AlertDialog extends StatelessWidget {
/// Typically used to provide padding to the button bar between the button bar
/// and the edges of the dialog.
///
/// If are no [actions], then no padding will be included. The padding around
/// the button bar defaults to zero. It is also important to note that
/// [buttonPadding] may contribute to the padding on the edges of [actions] as
/// well.
/// If there are no [actions], then no padding will be included. It is also
/// important to note that [buttonPadding] may contribute to the padding on
/// the edges of [actions] as well.
///
/// {@tool snippet}
/// This is an example of a set of actions aligned with the content widget.
......@@ -373,7 +372,7 @@ class AlertDialog extends StatelessWidget {
/// See also:
///
/// * [OverflowBar], which [actions] configures to lay itself out.
final EdgeInsetsGeometry actionsPadding;
final EdgeInsetsGeometry? actionsPadding;
/// Defines the horizontal layout of the [actions] according to the same
/// rules as for [Row.mainAxisAlignment].
......@@ -507,8 +506,6 @@ class AlertDialog extends StatelessWidget {
// children.
final double paddingScaleFactor = _paddingScaleFactor(MediaQuery.of(context).textScaleFactor);
final TextDirection? textDirection = Directionality.maybeOf(context);
const double m3ActionEndPadding = 18.0;
const double m3ActionBottomPadding = 12.0;
Widget? titleWidget;
Widget? contentWidget;
......@@ -557,14 +554,11 @@ 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: theme.useMaterial3
? actionsPadding.add(EdgeInsets.all(spacing))
.add(const EdgeInsets.only(
right: m3ActionEndPadding,
bottom: m3ActionBottomPadding,
))
: actionsPadding.add(EdgeInsets.all(spacing)),
padding: effetiveActionsPadding,
child: OverflowBar(
alignment: actionsAlignment ?? MainAxisAlignment.end,
spacing: spacing,
......
......@@ -15,16 +15,13 @@ import 'theme.dart';
/// `DialogTheme.of(context)`. Instances of [DialogTheme] can be customized with
/// [DialogTheme.copyWith].
///
/// When Shape is `null`, the dialog defaults to a [RoundedRectangleBorder] with
/// a border radius of 2.0 on all corners.
///
/// [titleTextStyle] and [contentTextStyle] are used in [AlertDialog]s.
/// If null, they default to [TextTheme.headline6] and [TextTheme.subtitle1],
/// respectively.
/// [titleTextStyle] and [contentTextStyle] are used in [AlertDialog]s and [SimpleDialog]s.
///
/// See also:
///
/// * [Dialog], a Material Design dialog that can be customized using this [DialogTheme].
/// * [Dialog], a dialog that can be customized using this [DialogTheme].
/// * [AlertDialog], a dialog that can be customized using this [DialogTheme].
/// * [SimpleDialog], a dialog that can be customized using this [DialogTheme].
/// * [ThemeData], which describes the overall theme information for the
/// application.
@immutable
......@@ -39,33 +36,24 @@ class DialogTheme with Diagnosticable {
this.contentTextStyle,
});
/// Default value for [Dialog.backgroundColor].
///
/// If null, [ThemeData.dialogBackgroundColor] is used, if that's null,
/// defaults to [Colors.white].
/// Overrides the default value for [Dialog.backgroundColor].
final Color? backgroundColor;
/// Default value for [Dialog.elevation].
///
/// If null, the [Dialog] elevation defaults to `24.0`.
/// Overrides the default value for [Dialog.elevation].
final double? elevation;
/// Default value for [Dialog.shape].
/// Overrides the default value for [Dialog.shape].
final ShapeBorder? shape;
/// Default value for [Dialog.alignment].
///
/// If null, the [Dialog] alignment defaults to [Alignment.center].
/// Overrides the default value for [Dialog.alignment].
final AlignmentGeometry? alignment;
/// Used to configure the [DefaultTextStyle] for the [AlertDialog.title] widget.
///
/// If null, defaults to [TextTheme.headline6] of [ThemeData.textTheme].
/// Overrides the default value for [DefaultTextStyle] for [SimpleDialog.title] and
/// [AlertDialog.title].
final TextStyle? titleTextStyle;
/// Used to configure the [DefaultTextStyle] for the [AlertDialog.content] widget.
///
/// If null, defaults to [TextTheme.subtitle1] of [ThemeData.textTheme].
/// Overrides the default value for [DefaultTextStyle] for [SimpleDialog.children] and
/// [AlertDialog.content].
final TextStyle? contentTextStyle;
/// Creates a copy of this object but with the given fields replaced with the
......
......@@ -658,25 +658,25 @@ void main() {
// First button
expect(
tester.getTopRight(find.byKey(key1)).dy,
tester.getTopRight(_findButtonBar()).dy + 8.0,
tester.getTopRight(_findButtonBar()).dy,
); // top
expect(
tester.getBottomRight(find.byKey(key1)).dy,
tester.getBottomRight(_findButtonBar()).dy - 20.0,
tester.getBottomRight(_findButtonBar()).dy - 24.0,
); // bottom
// // Second button
expect(
tester.getTopRight(find.byKey(key2)).dy,
tester.getTopRight(_findButtonBar()).dy + 8.0,
tester.getTopRight(_findButtonBar()).dy,
); // top
expect(
tester.getBottomRight(find.byKey(key2)).dy,
tester.getBottomRight(_findButtonBar()).dy - 20.0,
tester.getBottomRight(_findButtonBar()).dy - 24.0,
); // bottom
expect(
tester.getBottomRight(find.byKey(key2)).dx,
tester.getBottomRight(_findButtonBar()).dx - 26.0,
tester.getBottomRight(_findButtonBar()).dx - 24.0,
); // right
});
......
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