From 9296a527b3262cdf1a60802b2a4518694c0bb983 Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Thu, 11 Feb 2021 18:33:24 -0800 Subject: [PATCH] Revert "Removed ButtonBar from AlertDialog (#75676)" (#75873) This reverts commit 705cebb239a05bcdf69c6eeae6d31eda7fa24895. --- packages/flutter/lib/src/material/dialog.dart | 22 ++++++------- .../flutter/test/material/dialog_test.dart | 33 ++++++++----------- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/packages/flutter/lib/src/material/dialog.dart b/packages/flutter/lib/src/material/dialog.dart index b1d01fab59..e77f99776a 100644 --- a/packages/flutter/lib/src/material/dialog.dart +++ b/packages/flutter/lib/src/material/dialog.dart @@ -424,8 +424,13 @@ class AlertDialog extends StatelessWidget { /// This is different from [actionsPadding], which defines the padding /// between the entire button bar and the edges of the dialog. /// - /// If this property is null, then it will default to + /// If this property is null, then it will use the surrounding + /// [ButtonBarThemeData.buttonPadding]. If that is null, it will default to /// 8.0 logical pixels on the left and right. + /// + /// See also: + /// + /// * [ButtonBar], which [actions] configures to lay itself out. final EdgeInsetsGeometry? buttonPadding; /// {@macro flutter.material.dialog.backgroundColor} @@ -533,18 +538,13 @@ class AlertDialog extends StatelessWidget { if (actions != null) { - final double spacing = (buttonPadding?.horizontal ?? 16) / 2; actionsWidget = Padding( padding: actionsPadding, - child: Container( - alignment: AlignmentDirectional.centerEnd, - padding: EdgeInsets.all(spacing), - child: OverflowBar( - spacing: spacing, - overflowDirection: actionsOverflowDirection ?? VerticalDirection.down, - overflowSpacing: actionsOverflowButtonSpacing ?? 0, - children: actions!, - ), + child: ButtonBar( + buttonPadding: buttonPadding, + overflowDirection: actionsOverflowDirection, + overflowButtonSpacing: actionsOverflowButtonSpacing, + children: actions!, ), ); } diff --git a/packages/flutter/test/material/dialog_test.dart b/packages/flutter/test/material/dialog_test.dart index fd8adb591f..6547ba6f55 100644 --- a/packages/flutter/test/material/dialog_test.dart +++ b/packages/flutter/test/material/dialog_test.dart @@ -46,13 +46,6 @@ RenderParagraph _getTextRenderObjectFromDialog(WidgetTester tester, String text) return tester.element(find.descendant(of: find.byType(Dialog), matching: find.text(text))).renderObject! as RenderParagraph; } -// What was the AlertDialog's ButtonBar when many of these tests were written, -// is now a Container with an OverflowBar child. The Container's size and location -// match the original ButtonBar's size and location. -Finder _findButtonBar() { - return find.ancestor(of: find.byType(OverflowBar), matching: find.byType(Container)).first; -} - const ShapeBorder _defaultDialogShape = RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0))); void main() { @@ -502,7 +495,7 @@ void main() { matching: find.byType(Material), ).first, ); - final Size actionsSize = tester.getSize(_findButtonBar()); + final Size actionsSize = tester.getSize(find.byType(ButtonBar)); expect(actionsSize.width, dialogSize.width); }); @@ -536,7 +529,7 @@ void main() { matching: find.byType(Material), ).first, ); - final Size actionsSize = tester.getSize(_findButtonBar()); + final Size actionsSize = tester.getSize(find.byType(ButtonBar)); expect(actionsSize.width, dialogSize.width - (30.0 * 2)); }); @@ -579,25 +572,25 @@ void main() { // First button expect( tester.getTopRight(find.byKey(key1)).dy, - tester.getTopRight(_findButtonBar()).dy + 8.0, + tester.getTopRight(find.byType(ButtonBar)).dy + 8.0, ); // top expect( tester.getBottomRight(find.byKey(key1)).dy, - tester.getBottomRight(_findButtonBar()).dy - 8.0, + tester.getBottomRight(find.byType(ButtonBar)).dy - 8.0, ); // bottom // Second button expect( tester.getTopRight(find.byKey(key2)).dy, - tester.getTopRight(_findButtonBar()).dy + 8.0, + tester.getTopRight(find.byType(ButtonBar)).dy + 8.0, ); // top expect( tester.getBottomRight(find.byKey(key2)).dy, - tester.getBottomRight(_findButtonBar()).dy - 8.0, + tester.getBottomRight(find.byType(ButtonBar)).dy - 8.0, ); // bottom expect( tester.getBottomRight(find.byKey(key2)).dx, - tester.getBottomRight(_findButtonBar()).dx - 8.0, + tester.getBottomRight(find.byType(ButtonBar)).dx - 8.0, ); // right }); @@ -643,25 +636,25 @@ void main() { // First button expect( tester.getTopRight(find.byKey(key1)).dy, - tester.getTopRight(_findButtonBar()).dy + ((10.0 + 20.0) / 2), + tester.getTopRight(find.byType(ButtonBar)).dy + ((10.0 + 20.0) / 2), ); // top expect( tester.getBottomRight(find.byKey(key1)).dy, - tester.getBottomRight(_findButtonBar()).dy - ((10.0 + 20.0) / 2), + tester.getBottomRight(find.byType(ButtonBar)).dy - ((10.0 + 20.0) / 2), ); // bottom // Second button expect( tester.getTopRight(find.byKey(key2)).dy, - tester.getTopRight(_findButtonBar()).dy + ((10.0 + 20.0) / 2), + tester.getTopRight(find.byType(ButtonBar)).dy + ((10.0 + 20.0) / 2), ); // top expect( tester.getBottomRight(find.byKey(key2)).dy, - tester.getBottomRight(_findButtonBar()).dy - ((10.0 + 20.0) / 2), + tester.getBottomRight(find.byType(ButtonBar)).dy - ((10.0 + 20.0) / 2), ); // bottom expect( tester.getBottomRight(find.byKey(key2)).dx, - tester.getBottomRight(_findButtonBar()).dx - ((10.0 + 20.0) / 2), + tester.getBottomRight(find.byType(ButtonBar)).dx - ((10.0 + 20.0) / 2), ); // right }); @@ -682,7 +675,7 @@ void main() { final Finder dialogFinder = find.descendant(of: find.byType(Dialog), matching: find.byType(Material)).first; final Finder titleFinder = find.byKey(titleKey); final Finder contentFinder = find.byKey(contentKey); - final Finder actionsFinder = _findButtonBar(); + final Finder actionsFinder = find.byType(ButtonBar); final Finder childrenFinder = find.byKey(childrenKey); Future openDialog(WidgetTester tester, Widget dialog, double textScaleFactor) async {