Skip to content

Commit 638aae7

Browse files
authored
Add alignment parameter for persistentFooterButtons (#101297)
1 parent 44be0b8 commit 638aae7

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

packages/flutter/lib/src/material/scaffold.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,7 @@ class Scaffold extends StatefulWidget {
14631463
this.floatingActionButtonLocation,
14641464
this.floatingActionButtonAnimator,
14651465
this.persistentFooterButtons,
1466+
this.persistentFooterAlignment = AlignmentDirectional.centerEnd,
14661467
this.drawer,
14671468
this.onDrawerChanged,
14681469
this.endDrawer,
@@ -1569,6 +1570,11 @@ class Scaffold extends StatefulWidget {
15691570
/// [bottomNavigationBar] but below the [body].
15701571
final List<Widget>? persistentFooterButtons;
15711572

1573+
/// The alignment of the [persistentFooterButtons] inside the [OverflowBar].
1574+
///
1575+
/// Defaults to [AlignmentDirectional.centerEnd].
1576+
final AlignmentDirectional persistentFooterAlignment;
1577+
15721578
/// A panel displayed to the side of the [body], often hidden on mobile
15731579
/// devices. Swipes in from either left-to-right ([TextDirection.ltr]) or
15741580
/// right-to-left ([TextDirection.rtl])
@@ -2725,7 +2731,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
27252731
top: false,
27262732
child: IntrinsicHeight(
27272733
child: Container(
2728-
alignment: AlignmentDirectional.centerEnd,
2734+
alignment: widget.persistentFooterAlignment,
27292735
padding: const EdgeInsets.all(8),
27302736
child: OverflowBar(
27312737
spacing: 8,

packages/flutter/test/material/scaffold_test.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,41 @@ void main() {
533533
expect(didPressButton, isTrue);
534534
});
535535

536+
testWidgets('Persistent bottom buttons alignment', (WidgetTester tester) async {
537+
Widget buildApp(AlignmentDirectional persistentAligment) {
538+
return MaterialApp(
539+
home: Scaffold(
540+
body: SingleChildScrollView(
541+
child: Container(
542+
color: Colors.amber[500],
543+
height: 5000.0,
544+
child: const Text('body'),
545+
),
546+
),
547+
persistentFooterAlignment: persistentAligment,
548+
persistentFooterButtons: <Widget>[
549+
TextButton(
550+
onPressed: () { },
551+
child: const Text('X'),
552+
),
553+
],
554+
),
555+
);
556+
}
557+
558+
await tester.pumpWidget(buildApp(AlignmentDirectional.centerEnd));
559+
Finder footerButton = find.byType(TextButton);
560+
expect(tester.getTopRight(footerButton).dx, 800.0 - 8.0);
561+
562+
await tester.pumpWidget(buildApp(AlignmentDirectional.center));
563+
footerButton = find.byType(TextButton);
564+
expect(tester.getCenter(footerButton).dx, 800.0 / 2);
565+
566+
await tester.pumpWidget(buildApp(AlignmentDirectional.centerStart));
567+
footerButton = find.byType(TextButton);
568+
expect(tester.getTopLeft(footerButton).dx, 8.0);
569+
});
570+
536571
testWidgets('Persistent bottom buttons apply media padding', (WidgetTester tester) async {
537572
await tester.pumpWidget(
538573
Directionality(

0 commit comments

Comments
 (0)