Add actionsOverflowAlignment parameter to dialog (#95995)
This commit is contained in:
@@ -261,6 +261,7 @@ class AlertDialog extends StatelessWidget {
|
|||||||
this.actions,
|
this.actions,
|
||||||
this.actionsPadding = EdgeInsets.zero,
|
this.actionsPadding = EdgeInsets.zero,
|
||||||
this.actionsAlignment,
|
this.actionsAlignment,
|
||||||
|
this.actionsOverflowAlignment,
|
||||||
this.actionsOverflowDirection,
|
this.actionsOverflowDirection,
|
||||||
this.actionsOverflowButtonSpacing,
|
this.actionsOverflowButtonSpacing,
|
||||||
this.buttonPadding,
|
this.buttonPadding,
|
||||||
@@ -375,6 +376,21 @@ class AlertDialog extends StatelessWidget {
|
|||||||
/// is used.
|
/// is used.
|
||||||
final MainAxisAlignment? actionsAlignment;
|
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
|
/// The vertical direction of [actions] if the children overflow
|
||||||
/// horizontally.
|
/// horizontally.
|
||||||
///
|
///
|
||||||
@@ -535,7 +551,7 @@ class AlertDialog extends StatelessWidget {
|
|||||||
child: OverflowBar(
|
child: OverflowBar(
|
||||||
alignment: actionsAlignment ?? MainAxisAlignment.end,
|
alignment: actionsAlignment ?? MainAxisAlignment.end,
|
||||||
spacing: spacing,
|
spacing: spacing,
|
||||||
overflowAlignment: OverflowBarAlignment.end,
|
overflowAlignment: actionsOverflowAlignment ?? OverflowBarAlignment.end,
|
||||||
overflowDirection: actionsOverflowDirection ?? VerticalDirection.down,
|
overflowDirection: actionsOverflowDirection ?? VerticalDirection.down,
|
||||||
overflowSpacing: actionsOverflowButtonSpacing ?? 0,
|
overflowSpacing: actionsOverflowButtonSpacing ?? 0,
|
||||||
children: actions!,
|
children: actions!,
|
||||||
|
|||||||
@@ -1184,6 +1184,40 @@ void main() {
|
|||||||
expect(buttonOneRect.bottom, buttonTwoRect.top - 10.0);
|
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 {
|
testWidgets('Dialogs removes MediaQuery padding and view insets', (WidgetTester tester) async {
|
||||||
late BuildContext outerContext;
|
late BuildContext outerContext;
|
||||||
late BuildContext routeContext;
|
late BuildContext routeContext;
|
||||||
|
|||||||
Reference in New Issue
Block a user