Skip to content

Commit 33cdd8e

Browse files
Feat: Add persistentFooterDecoration for scaffold (#167524)
Feat: Add persistentFooterDecoration for scaffold fixes: #166478 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: Tong Mu <[email protected]>
1 parent f7354da commit 33cdd8e

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,7 @@ class Scaffold extends StatefulWidget {
16971697
this.floatingActionButtonAnimator,
16981698
this.persistentFooterButtons,
16991699
this.persistentFooterAlignment = AlignmentDirectional.centerEnd,
1700+
this.persistentFooterDecoration,
17001701
this.drawer,
17011702
this.onDrawerChanged,
17021703
this.endDrawer,
@@ -1814,6 +1815,17 @@ class Scaffold extends StatefulWidget {
18141815
/// Defaults to [AlignmentDirectional.centerEnd].
18151816
final AlignmentDirectional persistentFooterAlignment;
18161817

1818+
/// Decoration for the container that holds the [persistentFooterButtons].
1819+
///
1820+
/// By default, this container has a top border with a width of 1.0, created by
1821+
/// [Divider.createBorderSide].
1822+
///
1823+
/// See also:
1824+
///
1825+
/// * [persistentFooterButtons], which defines the buttons to show in the footer.
1826+
/// * [persistentFooterAlignment], which defines the alignment of the footer buttons.
1827+
final BoxDecoration? persistentFooterDecoration;
1828+
18171829
/// A panel displayed to the side of the [body], often hidden on mobile
18181830
/// devices. Swipes in from either left-to-right ([TextDirection.ltr]) or
18191831
/// right-to-left ([TextDirection.rtl])
@@ -3058,9 +3070,9 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
30583070
_addIfNonNull(
30593071
children,
30603072
Container(
3061-
decoration: BoxDecoration(
3062-
border: Border(top: Divider.createBorderSide(context, width: 1.0)),
3063-
),
3073+
decoration:
3074+
widget.persistentFooterDecoration ??
3075+
BoxDecoration(border: Border(top: Divider.createBorderSide(context, width: 1.0))),
30643076
child: SafeArea(
30653077
top: false,
30663078
child: IntrinsicHeight(

packages/flutter/test/material/scaffold_test.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,33 @@ void main() {
823823
expect(initialPoint, finalPoint);
824824
});
825825

826+
testWidgets('Persistent bottom buttons can apply decoration', (WidgetTester tester) async {
827+
await tester.pumpWidget(
828+
Directionality(
829+
textDirection: TextDirection.ltr,
830+
child: MediaQuery(
831+
data: const MediaQueryData(padding: EdgeInsets.fromLTRB(10.0, 20.0, 30.0, 40.0)),
832+
child: Scaffold(
833+
body: SingleChildScrollView(
834+
child: Container(color: Colors.amber[500], height: 5000.0, child: const Text('body')),
835+
),
836+
persistentFooterDecoration: const BoxDecoration(
837+
border: Border(top: BorderSide(color: Colors.red)),
838+
),
839+
persistentFooterButtons: const <Widget>[Placeholder()],
840+
),
841+
),
842+
),
843+
);
844+
845+
final Finder persistentFooter =
846+
find.ancestor(of: find.byType(OverflowBar), matching: find.byType(Container)).first;
847+
final Decoration decoration = tester.widget<Container>(persistentFooter).decoration!;
848+
849+
expect(decoration, isA<BoxDecoration>());
850+
expect((decoration as BoxDecoration).border!.top.color, Colors.red);
851+
});
852+
826853
group('back arrow', () {
827854
Future<void> expectBackIcon(WidgetTester tester, IconData expectedIcon) async {
828855
final GlobalKey rootKey = GlobalKey();

0 commit comments

Comments
 (0)