diff --git a/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart b/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart index 21ae3e1d2c..4e1f18e291 100644 --- a/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart +++ b/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart @@ -156,7 +156,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget { @override Widget build(BuildContext context) { assert(debugCheckHasMediaQuery(context)); - final double bottomPadding = MediaQuery.of(context).padding.bottom; + final double bottomPadding = MediaQuery.of(context).viewPadding.bottom; final Color backgroundColor = CupertinoDynamicColor.resolve( this.backgroundColor ?? CupertinoTheme.of(context).barBackgroundColor, diff --git a/packages/flutter/lib/src/material/bottom_navigation_bar.dart b/packages/flutter/lib/src/material/bottom_navigation_bar.dart index ced7dc5aaf..9b027b11d9 100644 --- a/packages/flutter/lib/src/material/bottom_navigation_bar.dart +++ b/packages/flutter/lib/src/material/bottom_navigation_bar.dart @@ -1114,7 +1114,7 @@ class _BottomNavigationBarState extends State with TickerPr final BottomNavigationBarLandscapeLayout layout = widget.landscapeLayout ?? bottomTheme.landscapeLayout ?? BottomNavigationBarLandscapeLayout.spread; - final double additionalBottomPadding = MediaQuery.of(context).padding.bottom; + final double additionalBottomPadding = MediaQuery.of(context).viewPadding.bottom; Color? backgroundColor; switch (_effectiveType) { diff --git a/packages/flutter/test/cupertino/bottom_tab_bar_test.dart b/packages/flutter/test/cupertino/bottom_tab_bar_test.dart index ab53e075d0..c78d8c997e 100644 --- a/packages/flutter/test/cupertino/bottom_tab_bar_test.dart +++ b/packages/flutter/test/cupertino/bottom_tab_bar_test.dart @@ -316,7 +316,7 @@ Future main() async { // Verify height with bottom padding. await pumpWidgetWithBoilerplate(tester, MediaQuery( - data: const MediaQueryData(padding: EdgeInsets.only(bottom: 40.0)), + data: const MediaQueryData(viewPadding: EdgeInsets.only(bottom: 40.0)), child: CupertinoTabScaffold( tabBar: tabBar, tabBuilder: (BuildContext context, int index) { @@ -359,7 +359,7 @@ Future main() async { // Verify height with bottom padding. const double bottomPadding = 40.0; await pumpWidgetWithBoilerplate(tester, MediaQuery( - data: const MediaQueryData(padding: EdgeInsets.only(bottom: bottomPadding)), + data: const MediaQueryData(viewPadding: EdgeInsets.only(bottom: bottomPadding)), child: CupertinoTabScaffold( tabBar: tabBar, tabBuilder: (BuildContext context, int index) { @@ -370,6 +370,60 @@ Future main() async { expect(tester.getSize(find.byType(CupertinoTabBar)).height, tabBarHeight + bottomPadding); }); + testWidgets('Ensure bar height will not change when toggle keyboard', (WidgetTester tester) async { + const double tabBarHeight = 56.0; + final CupertinoTabBar tabBar = CupertinoTabBar( + height: tabBarHeight, + items: [ + BottomNavigationBarItem( + icon: ImageIcon(MemoryImage(Uint8List.fromList(kTransparentImage))), + label: 'Aka', + ), + BottomNavigationBarItem( + icon: ImageIcon(MemoryImage(Uint8List.fromList(kTransparentImage))), + label: 'Shiro', + ), + ], + ); + + const double bottomPadding = 34.0; + + // Test the height is correct when keyboard not showing. + // So viewInset should be 0.0. + await pumpWidgetWithBoilerplate(tester, MediaQuery( + data: const MediaQueryData( + padding: EdgeInsets.only(bottom: bottomPadding), + viewPadding: EdgeInsets.only(bottom: bottomPadding), + ), + child: CupertinoTabScaffold( + tabBar: tabBar, + tabBuilder: (BuildContext context, int index) { + return const Placeholder(); + }, + ), + )); + expect(tester.getSize(find.byType(CupertinoTabBar)).height, tabBarHeight + bottomPadding); + + // Now show keyboard, and test the bar height will not change. + await pumpWidgetWithBoilerplate(tester, + MediaQuery( + data: const MediaQueryData( + viewPadding: EdgeInsets.only(bottom: bottomPadding), + viewInsets: EdgeInsets.only(bottom: 336.0), + ), + child: CupertinoTabScaffold( + tabBar: tabBar, + tabBuilder: (BuildContext context, int index) { + return const Placeholder(); + }, + ), + ), + ); + + // Expect the bar height should not change. + expect(tester.getSize(find.byType(CupertinoTabBar)).height, tabBarHeight + bottomPadding); + }); + testWidgets('Opaque background does not add blur effects', (WidgetTester tester) async { await pumpWidgetWithBoilerplate(tester, MediaQuery( data: const MediaQueryData(), diff --git a/packages/flutter/test/material/bottom_navigation_bar_test.dart b/packages/flutter/test/material/bottom_navigation_bar_test.dart index 6419252a67..afc87811c0 100644 --- a/packages/flutter/test/material/bottom_navigation_bar_test.dart +++ b/packages/flutter/test/material/bottom_navigation_bar_test.dart @@ -991,7 +991,7 @@ void main() { await tester.pumpWidget( MaterialApp( home: MediaQuery( - data: const MediaQueryData(padding: EdgeInsets.only(bottom: 40.0)), + data: const MediaQueryData(viewPadding: EdgeInsets.only(bottom: 40.0)), child: Scaffold( bottomNavigationBar: BottomNavigationBar( items: const [ @@ -1018,7 +1018,7 @@ void main() { await tester.pumpWidget( MaterialApp( home: MediaQuery( - data: const MediaQueryData(padding: EdgeInsets.only(bottom: 40.0)), + data: const MediaQueryData(viewPadding: EdgeInsets.only(bottom: 40.0)), child: Scaffold( bottomNavigationBar: BottomNavigationBar( selectedFontSize: 8, @@ -1042,6 +1042,58 @@ void main() { expect(tester.getSize(find.byType(BottomNavigationBar)).height, expectedHeight); }); + testWidgets('BottomNavigationBar height will not change when toggle keyboard', (WidgetTester tester) async { + + final Widget child = Scaffold( + bottomNavigationBar: BottomNavigationBar( + selectedFontSize: 8, + items: const [ + BottomNavigationBarItem( + icon: Icon(Icons.ac_unit), + label: 'AC', + ), + BottomNavigationBarItem( + icon: Icon(Icons.access_alarm), + label: 'Alarm', + ), + ], + ), + ); + + // Test the bar height is correct when not showing the keyboard. + await tester.pumpWidget( + MaterialApp( + home: MediaQuery( + data: const MediaQueryData( + viewPadding: EdgeInsets.only(bottom: 40.0), + padding: EdgeInsets.only(bottom: 40.0), + ), + child: child, + ), + ), + ); + + // Expect the height is the correct. + const double expectedHeight = kBottomNavigationBarHeight + 40.0; + expect(tester.getSize(find.byType(BottomNavigationBar)).height, expectedHeight); + + // Now we show the keyboard. + await tester.pumpWidget( + MaterialApp( + home: MediaQuery( + data: const MediaQueryData( + viewPadding: EdgeInsets.only(bottom: 40.0), + viewInsets: EdgeInsets.only(bottom: 336.0), + ), + child: child, + ), + ), + ); + + // Expect the height is the same. + expect(tester.getSize(find.byType(BottomNavigationBar)).height, expectedHeight); + }); + testWidgets('BottomNavigationBar action size test', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( diff --git a/packages/flutter/test/material/scaffold_test.dart b/packages/flutter/test/material/scaffold_test.dart index 4793cf7a3a..d63ed5476f 100644 --- a/packages/flutter/test/material/scaffold_test.dart +++ b/packages/flutter/test/material/scaffold_test.dart @@ -672,7 +672,7 @@ void main() { 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), + viewPadding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 40.0), ), child: Scaffold( body: SingleChildScrollView(