diff --git a/packages/flutter/lib/src/material/dialog.dart b/packages/flutter/lib/src/material/dialog.dart index 128e56c3a9d..a3999de2e4e 100644 --- a/packages/flutter/lib/src/material/dialog.dart +++ b/packages/flutter/lib/src/material/dialog.dart @@ -261,6 +261,7 @@ class AlertDialog extends StatelessWidget { this.actions, this.actionsPadding = EdgeInsets.zero, this.actionsAlignment, + this.actionsOverflowAlignment, this.actionsOverflowDirection, this.actionsOverflowButtonSpacing, this.buttonPadding, @@ -375,6 +376,21 @@ class AlertDialog extends StatelessWidget { /// is used. final MainAxisAlignment? actionsAlignment; + /// The horizontal alignment of [actions] within the vertical + /// "overflow" layout. + /// + /// If the dialog's [actions] do not fit into a single row, then they + /// are arranged in a column. This parameter controls the horizontal + /// alignment of widgets in the case of an overflow. + /// + /// If this parameter is null (the default) then [OverflowBarAlignment.end] + /// is used. + /// + /// See also: + /// + /// * [OverflowBar], which [actions] configures to lay itself out. + final OverflowBarAlignment? actionsOverflowAlignment; + /// The vertical direction of [actions] if the children overflow /// horizontally. /// @@ -535,7 +551,7 @@ class AlertDialog extends StatelessWidget { child: OverflowBar( alignment: actionsAlignment ?? MainAxisAlignment.end, spacing: spacing, - overflowAlignment: OverflowBarAlignment.end, + overflowAlignment: actionsOverflowAlignment ?? OverflowBarAlignment.end, overflowDirection: actionsOverflowDirection ?? VerticalDirection.down, overflowSpacing: actionsOverflowButtonSpacing ?? 0, children: actions!, diff --git a/packages/flutter/test/material/dialog_test.dart b/packages/flutter/test/material/dialog_test.dart index a6f4763547d..591d734bfa9 100644 --- a/packages/flutter/test/material/dialog_test.dart +++ b/packages/flutter/test/material/dialog_test.dart @@ -1184,6 +1184,40 @@ void main() { expect(buttonOneRect.bottom, buttonTwoRect.top - 10.0); }); + testWidgets('Dialogs can set the alignment of the OverflowBar', (WidgetTester tester) async { + final GlobalKey key1 = GlobalKey(); + final GlobalKey key2 = GlobalKey(); + + final AlertDialog dialog = AlertDialog( + title: const Text('title'), + content: const Text('content'), + actions: [ + ElevatedButton( + key: key1, + onPressed: () {}, + child: const Text('Loooooooooog button 1'), + ), + ElevatedButton( + key: key2, + onPressed: () {}, + child: const Text('Loooooooooooooonger button 2'), + ), + ], + actionsOverflowAlignment: OverflowBarAlignment.center, + ); + + await tester.pumpWidget( + _buildAppWithDialog(dialog), + ); + + await tester.tap(find.text('X')); + await tester.pumpAndSettle(); + + final Rect buttonOneRect = tester.getRect(find.byKey(key1)); + final Rect buttonTwoRect = tester.getRect(find.byKey(key2)); + expect(buttonOneRect.center.dx, buttonTwoRect.center.dx); + }); + testWidgets('Dialogs removes MediaQuery padding and view insets', (WidgetTester tester) async { late BuildContext outerContext; late BuildContext routeContext;