diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index d60904d04a..3eef5e3e71 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -1463,6 +1463,7 @@ class Scaffold extends StatefulWidget { this.floatingActionButtonLocation, this.floatingActionButtonAnimator, this.persistentFooterButtons, + this.persistentFooterAlignment = AlignmentDirectional.centerEnd, this.drawer, this.onDrawerChanged, this.endDrawer, @@ -1569,6 +1570,11 @@ class Scaffold extends StatefulWidget { /// [bottomNavigationBar] but below the [body]. final List? persistentFooterButtons; + /// The alignment of the [persistentFooterButtons] inside the [OverflowBar]. + /// + /// Defaults to [AlignmentDirectional.centerEnd]. + final AlignmentDirectional persistentFooterAlignment; + /// A panel displayed to the side of the [body], often hidden on mobile /// devices. Swipes in from either left-to-right ([TextDirection.ltr]) or /// right-to-left ([TextDirection.rtl]) @@ -2725,7 +2731,7 @@ class ScaffoldState extends State with TickerProviderStateMixin, Resto top: false, child: IntrinsicHeight( child: Container( - alignment: AlignmentDirectional.centerEnd, + alignment: widget.persistentFooterAlignment, padding: const EdgeInsets.all(8), child: OverflowBar( spacing: 8, diff --git a/packages/flutter/test/material/scaffold_test.dart b/packages/flutter/test/material/scaffold_test.dart index e34cdff3bb..3a10ba8c08 100644 --- a/packages/flutter/test/material/scaffold_test.dart +++ b/packages/flutter/test/material/scaffold_test.dart @@ -533,6 +533,41 @@ void main() { expect(didPressButton, isTrue); }); + testWidgets('Persistent bottom buttons alignment', (WidgetTester tester) async { + Widget buildApp(AlignmentDirectional persistentAligment) { + return MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: Container( + color: Colors.amber[500], + height: 5000.0, + child: const Text('body'), + ), + ), + persistentFooterAlignment: persistentAligment, + persistentFooterButtons: [ + TextButton( + onPressed: () { }, + child: const Text('X'), + ), + ], + ), + ); + } + + await tester.pumpWidget(buildApp(AlignmentDirectional.centerEnd)); + Finder footerButton = find.byType(TextButton); + expect(tester.getTopRight(footerButton).dx, 800.0 - 8.0); + + await tester.pumpWidget(buildApp(AlignmentDirectional.center)); + footerButton = find.byType(TextButton); + expect(tester.getCenter(footerButton).dx, 800.0 / 2); + + await tester.pumpWidget(buildApp(AlignmentDirectional.centerStart)); + footerButton = find.byType(TextButton); + expect(tester.getTopLeft(footerButton).dx, 8.0); + }); + testWidgets('Persistent bottom buttons apply media padding', (WidgetTester tester) async { await tester.pumpWidget( Directionality(