diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index 6c7d9f66d8..23d22f504d 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -2978,7 +2978,7 @@ class ScaffoldState extends State with TickerProviderStateMixin, Resto removeLeftPadding: false, removeTopPadding: true, removeRightPadding: false, - removeBottomPadding: false, + removeBottomPadding: widget.bottomNavigationBar != null, maintainBottomViewPadding: !_resizeToAvoidBottomInset, ); } diff --git a/packages/flutter/test/material/scaffold_test.dart b/packages/flutter/test/material/scaffold_test.dart index 139a372c14..d1d372a51f 100644 --- a/packages/flutter/test/material/scaffold_test.dart +++ b/packages/flutter/test/material/scaffold_test.dart @@ -497,6 +497,55 @@ void main() { expect(tester.getBottomRight(buttonsBar), const Offset(770.0, 560.0)); }); + testWidgets('persistentFooterButtons with bottomNavigationBar apply SafeArea properly', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/pull/92039 + await tester.pumpWidget( + MaterialApp( + home: MediaQuery( + data: const MediaQueryData( + // Representing a navigational notch at the bottom of the screen + padding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 40.0), + ), + child: Scaffold( + body: SingleChildScrollView( + child: Container( + color: Colors.amber[500], + height: 5000.0, + child: const Text('body'), + ), + ), + bottomNavigationBar: BottomNavigationBar( + items: const [ + BottomNavigationBarItem( + icon: Icon(Icons.home), + label: 'Home', + ), + BottomNavigationBarItem( + icon: Icon(Icons.business), + label: 'Business', + ), + BottomNavigationBarItem( + icon: Icon(Icons.school), + label: 'School', + ), + ], + ), + persistentFooterButtons: const [Placeholder()], + ), + ), + ), + ); + + final Finder buttonsBar = find.ancestor(of: find.byType(OverflowBar), matching: find.byType(Padding)).first; + // The SafeArea of the persistentFooterButtons should not pad below them + // since they are stacked on top of the bottomNavigationBar. The + // bottomNavigationBar will handle the padding instead. + // 488 represents the height of the persistentFooterButtons, with the bottom + // of the screen being 600. If the 40 pixels of bottom padding were being + // errantly applied, the buttons would be higher (448). + expect(tester.getTopLeft(buttonsBar), const Offset(0.0, 488.0)); + }); + testWidgets('Persistent bottom buttons bottom padding is not consumed by viewInsets', (WidgetTester tester) async { final Widget child = Directionality( textDirection: TextDirection.ltr, @@ -974,15 +1023,15 @@ void main() { await tester.pump(const Duration(seconds: 1)); expect(tester.getRect(find.byKey(appBar)), const Rect.fromLTRB(0.0, 0.0, 800.0, 43.0)); - expect(tester.getRect(find.byKey(body)), const Rect.fromLTRB(0.0, 43.0, 800.0, 348.0)); - expect(tester.getRect(find.byKey(floatingActionButton)), rectMoreOrLessEquals(const Rect.fromLTRB(36.0, 255.0, 113.0, 332.0))); - expect(tester.getRect(find.byKey(persistentFooterButton)),const Rect.fromLTRB(28.0, 357.0, 128.0, 447.0)); // Note: has 8px each top/bottom padding. + expect(tester.getRect(find.byKey(body)), const Rect.fromLTRB(0.0, 43.0, 800.0, 400.0)); + expect(tester.getRect(find.byKey(floatingActionButton)), rectMoreOrLessEquals(const Rect.fromLTRB(36.0, 307.0, 113.0, 384.0))); + expect(tester.getRect(find.byKey(persistentFooterButton)),const Rect.fromLTRB(28.0, 417.0, 128.0, 507.0)); // Note: has 8px each top/bottom padding. expect(tester.getRect(find.byKey(drawer)), const Rect.fromLTRB(596.0, 0.0, 800.0, 600.0)); expect(tester.getRect(find.byKey(bottomNavigationBar)), const Rect.fromLTRB(0.0, 515.0, 800.0, 600.0)); expect(tester.getRect(find.byKey(insideAppBar)), const Rect.fromLTRB(20.0, 30.0, 750.0, 43.0)); - expect(tester.getRect(find.byKey(insideBody)), const Rect.fromLTRB(20.0, 43.0, 750.0, 348.0)); - expect(tester.getRect(find.byKey(insideFloatingActionButton)), rectMoreOrLessEquals(const Rect.fromLTRB(36.0, 255.0, 113.0, 332.0))); - expect(tester.getRect(find.byKey(insidePersistentFooterButton)), const Rect.fromLTRB(28.0, 357.0, 128.0, 447.0)); + expect(tester.getRect(find.byKey(insideBody)), const Rect.fromLTRB(20.0, 43.0, 750.0, 400.0)); + expect(tester.getRect(find.byKey(insideFloatingActionButton)), rectMoreOrLessEquals(const Rect.fromLTRB(36.0, 307.0, 113.0, 384.0))); + expect(tester.getRect(find.byKey(insidePersistentFooterButton)), const Rect.fromLTRB(28.0, 417.0, 128.0, 507.0)); expect(tester.getRect(find.byKey(insideDrawer)), const Rect.fromLTRB(596.0, 30.0, 750.0, 540.0)); expect(tester.getRect(find.byKey(insideBottomNavigationBar)), const Rect.fromLTRB(20.0, 515.0, 750.0, 540.0)); });