Add actionsOverflowAlignment parameter to dialog (#95995)

This commit is contained in:
Bencze Balázs 2022-02-23 02:26:20 +02:00 committed by GitHub
parent f4fc2c87f7
commit a1a5c1496c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 1 deletions

View File

@ -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!,

View File

@ -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: <Widget>[
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;