Unverified Commit 08e38cf2 authored by Jonathan Cole's avatar Jonathan Cole Committed by GitHub

Fix BottomNavigationBar MediaQuery padding (#75360)

parent c7ecd3fd
...@@ -1018,9 +1018,7 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr ...@@ -1018,9 +1018,7 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
assert(Overlay.of(context, debugRequiredFor: widget) != null); assert(Overlay.of(context, debugRequiredFor: widget) != null);
final BottomNavigationBarThemeData bottomTheme = BottomNavigationBarTheme.of(context); final BottomNavigationBarThemeData bottomTheme = BottomNavigationBarTheme.of(context);
final double additionalBottomPadding = MediaQuery.of(context).padding.bottom;
// Labels apply up to _bottomMargin padding. Remainder is media padding.
final double additionalBottomPadding = math.max(MediaQuery.of(context).padding.bottom - widget.selectedFontSize / 2.0, 0.0);
Color? backgroundColor; Color? backgroundColor;
switch (_effectiveType) { switch (_effectiveType) {
case BottomNavigationBarType.fixed: case BottomNavigationBarType.fixed:
......
...@@ -721,9 +721,35 @@ void main() { ...@@ -721,9 +721,35 @@ void main() {
), ),
); );
const double labelBottomMargin = 7.0; // 7 == defaulted selectedFontSize / 2.0. const double expectedHeight = kBottomNavigationBarHeight + 40.0;
const double additionalPadding = 40.0 - labelBottomMargin; expect(tester.getSize(find.byType(BottomNavigationBar)).height, expectedHeight);
const double expectedHeight = kBottomNavigationBarHeight + additionalPadding; });
testWidgets('BottomNavigationBar adds bottom padding to height with a custom font size', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: MediaQuery(
data: const MediaQueryData(padding: EdgeInsets.only(bottom: 40.0)),
child: Scaffold(
bottomNavigationBar: BottomNavigationBar(
selectedFontSize: 8,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.ac_unit),
label: 'AC',
),
BottomNavigationBarItem(
icon: Icon(Icons.access_alarm),
label: 'Alarm',
),
],
),
),
),
),
);
const double expectedHeight = kBottomNavigationBarHeight + 40.0;
expect(tester.getSize(find.byType(BottomNavigationBar)).height, expectedHeight); expect(tester.getSize(find.byType(BottomNavigationBar)).height, expectedHeight);
}); });
......
...@@ -684,7 +684,7 @@ void main() { ...@@ -684,7 +684,7 @@ void main() {
const double keyboardHeight = 200.0; const double keyboardHeight = 200.0;
const double viewPadding = 50.0; const double viewPadding = 50.0;
final Key floatingActionButton = UniqueKey(); final Key floatingActionButton = UniqueKey();
const double bottomNavHeight = 99.0; const double bottomNavHeight = 106.0;
// Default // Default
await tester.pumpWidget(_buildTest( await tester.pumpWidget(_buildTest(
location, location,
...@@ -929,7 +929,7 @@ void main() { ...@@ -929,7 +929,7 @@ void main() {
testWidgets('startFloat', (WidgetTester tester) async { testWidgets('startFloat', (WidgetTester tester) async {
const Rect defaultRect = Rect.fromLTRB(16.0, 478.0, 72.0, 534.0); const Rect defaultRect = Rect.fromLTRB(16.0, 478.0, 72.0, 534.0);
// Positioned relative to BottomNavigationBar // Positioned relative to BottomNavigationBar
const Rect bottomNavigationBarRect = Rect.fromLTRB(16.0, 429.0, 72.0, 485.0); const Rect bottomNavigationBarRect = Rect.fromLTRB(16.0, 422.0, 72.0, 478.0);
// Position relative to BottomSheet // Position relative to BottomSheet
const Rect bottomSheetRect = Rect.fromLTRB(16.0, 472.0, 72.0, 528.0); const Rect bottomSheetRect = Rect.fromLTRB(16.0, 472.0, 72.0, 528.0);
// Positioned relative to SnackBar // Positioned relative to SnackBar
...@@ -947,7 +947,7 @@ void main() { ...@@ -947,7 +947,7 @@ void main() {
testWidgets('miniStartFloat', (WidgetTester tester) async { testWidgets('miniStartFloat', (WidgetTester tester) async {
const Rect defaultRect = Rect.fromLTRB(12.0, 490.0, 60.0, 538.0); const Rect defaultRect = Rect.fromLTRB(12.0, 490.0, 60.0, 538.0);
// Positioned relative to BottomNavigationBar // Positioned relative to BottomNavigationBar
const Rect bottomNavigationBarRect = Rect.fromLTRB(12.0, 441.0, 60.0, 489.0); const Rect bottomNavigationBarRect = Rect.fromLTRB(12.0, 434.0, 60.0, 482.0);
// Positioned relative to BottomSheet // Positioned relative to BottomSheet
const Rect bottomSheetRect = Rect.fromLTRB(12.0, 480.0, 60.0, 528.0); const Rect bottomSheetRect = Rect.fromLTRB(12.0, 480.0, 60.0, 528.0);
// Positioned relative to SnackBar // Positioned relative to SnackBar
...@@ -966,7 +966,7 @@ void main() { ...@@ -966,7 +966,7 @@ void main() {
testWidgets('centerFloat', (WidgetTester tester) async { testWidgets('centerFloat', (WidgetTester tester) async {
const Rect defaultRect = Rect.fromLTRB(372.0, 478.0, 428.0, 534.0); const Rect defaultRect = Rect.fromLTRB(372.0, 478.0, 428.0, 534.0);
// Positioned relative to BottomNavigationBar // Positioned relative to BottomNavigationBar
const Rect bottomNavigationBarRect = Rect.fromLTRB(372.0, 429.0, 428.0, 485.0); const Rect bottomNavigationBarRect = Rect.fromLTRB(372.0, 422.0, 428.0, 478.0);
// Positioned relative to BottomSheet // Positioned relative to BottomSheet
const Rect bottomSheetRect = Rect.fromLTRB(372.0, 472.0, 428.0, 528.0); const Rect bottomSheetRect = Rect.fromLTRB(372.0, 472.0, 428.0, 528.0);
// Positioned relative to SnackBar // Positioned relative to SnackBar
...@@ -984,7 +984,7 @@ void main() { ...@@ -984,7 +984,7 @@ void main() {
testWidgets('miniCenterFloat', (WidgetTester tester) async { testWidgets('miniCenterFloat', (WidgetTester tester) async {
const Rect defaultRect = Rect.fromLTRB(376.0, 490.0, 424.0, 538.0); const Rect defaultRect = Rect.fromLTRB(376.0, 490.0, 424.0, 538.0);
// Positioned relative to BottomNavigationBar // Positioned relative to BottomNavigationBar
const Rect bottomNavigationBarRect = Rect.fromLTRB(376.0, 441.0, 424.0, 489.0); const Rect bottomNavigationBarRect = Rect.fromLTRB(376.0, 434.0, 424.0, 482.0);
// Positioned relative to BottomSheet // Positioned relative to BottomSheet
const Rect bottomSheetRect = Rect.fromLTRB(376.0, 480.0, 424.0, 528.0); const Rect bottomSheetRect = Rect.fromLTRB(376.0, 480.0, 424.0, 528.0);
// Positioned relative to SnackBar // Positioned relative to SnackBar
...@@ -1003,7 +1003,7 @@ void main() { ...@@ -1003,7 +1003,7 @@ void main() {
testWidgets('endFloat', (WidgetTester tester) async { testWidgets('endFloat', (WidgetTester tester) async {
const Rect defaultRect = Rect.fromLTRB(728.0, 478.0, 784.0, 534.0); const Rect defaultRect = Rect.fromLTRB(728.0, 478.0, 784.0, 534.0);
// Positioned relative to BottomNavigationBar // Positioned relative to BottomNavigationBar
const Rect bottomNavigationBarRect = Rect.fromLTRB(728.0, 429.0, 784.0, 485.0); const Rect bottomNavigationBarRect = Rect.fromLTRB(728.0, 422.0, 784.0, 478.0);
// Positioned relative to BottomSheet // Positioned relative to BottomSheet
const Rect bottomSheetRect = Rect.fromLTRB(728.0, 472.0, 784.0, 528.0); const Rect bottomSheetRect = Rect.fromLTRB(728.0, 472.0, 784.0, 528.0);
// Positioned relative to SnackBar // Positioned relative to SnackBar
...@@ -1021,7 +1021,7 @@ void main() { ...@@ -1021,7 +1021,7 @@ void main() {
testWidgets('miniEndFloat', (WidgetTester tester) async { testWidgets('miniEndFloat', (WidgetTester tester) async {
const Rect defaultRect = Rect.fromLTRB(740.0, 490.0, 788.0, 538.0); const Rect defaultRect = Rect.fromLTRB(740.0, 490.0, 788.0, 538.0);
// Positioned relative to BottomNavigationBar // Positioned relative to BottomNavigationBar
const Rect bottomNavigationBarRect = Rect.fromLTRB(740.0, 441.0, 788.0, 489.0); const Rect bottomNavigationBarRect = Rect.fromLTRB(740.0, 434.0, 788.0, 482.0);
// Positioned relative to BottomSheet // Positioned relative to BottomSheet
const Rect bottomSheetRect = Rect.fromLTRB(740.0, 480.0, 788.0, 528.0); const Rect bottomSheetRect = Rect.fromLTRB(740.0, 480.0, 788.0, 528.0);
// Positioned relative to SnackBar // Positioned relative to SnackBar
...@@ -1056,7 +1056,7 @@ void main() { ...@@ -1056,7 +1056,7 @@ void main() {
}) async { }) async {
const double keyboardHeight = 200.0; const double keyboardHeight = 200.0;
const double viewPadding = 50.0; const double viewPadding = 50.0;
const double bottomNavHeight = 99.0; const double bottomNavHeight = 106.0;
final Key floatingActionButton = UniqueKey(); final Key floatingActionButton = UniqueKey();
final double fabHeight = mini ? 48.0 : 56.0; final double fabHeight = mini ? 48.0 : 56.0;
// Default // Default
...@@ -1269,9 +1269,9 @@ void main() { ...@@ -1269,9 +1269,9 @@ void main() {
testWidgets('startDocked', (WidgetTester tester) async { testWidgets('startDocked', (WidgetTester tester) async {
const Rect defaultRect = Rect.fromLTRB(16.0, 494.0, 72.0, 550.0); const Rect defaultRect = Rect.fromLTRB(16.0, 494.0, 72.0, 550.0);
// Positioned relative to BottomNavigationBar // Positioned relative to BottomNavigationBar
const Rect bottomNavigationBarRect = Rect.fromLTRB(16.0, 473.0, 72.0, 529.0); const Rect bottomNavigationBarRect = Rect.fromLTRB(16.0, 466.0, 72.0, 522.0);
// Positioned relative to BottomNavigationBar & BottomSheet // Positioned relative to BottomNavigationBar & BottomSheet
const Rect bottomSheetRect = Rect.fromLTRB(16.0, 373.0, 72.0, 429.0); const Rect bottomSheetRect = Rect.fromLTRB(16.0, 366.0, 72.0, 422.0);
// Positioned relative to SnackBar // Positioned relative to SnackBar
const Rect snackBarRect = Rect.fromLTRB(16.0, 486.0, 72.0, 542.0); const Rect snackBarRect = Rect.fromLTRB(16.0, 486.0, 72.0, 542.0);
await _runDockedTests( await _runDockedTests(
...@@ -1287,9 +1287,9 @@ void main() { ...@@ -1287,9 +1287,9 @@ void main() {
testWidgets('miniStartDocked', (WidgetTester tester) async { testWidgets('miniStartDocked', (WidgetTester tester) async {
const Rect defaultRect = Rect.fromLTRB(12.0, 502.0, 60.0, 550.0); const Rect defaultRect = Rect.fromLTRB(12.0, 502.0, 60.0, 550.0);
// Positioned relative to BottomNavigationBar // Positioned relative to BottomNavigationBar
const Rect bottomNavigationBarRect = Rect.fromLTRB(12.0, 477.0, 60.0, 525.0); const Rect bottomNavigationBarRect = Rect.fromLTRB(12.0, 470.0, 60.0, 518.0);
// Positioned relative to BottomNavigationBar & BottomSheet // Positioned relative to BottomNavigationBar & BottomSheet
const Rect bottomSheetRect = Rect.fromLTRB(12.0, 377.0, 60.0, 425.0); const Rect bottomSheetRect = Rect.fromLTRB(12.0, 370.0, 60.0, 418.0);
// Positioned relative to SnackBar // Positioned relative to SnackBar
const Rect snackBarRect = Rect.fromLTRB(12.0, 494.0, 60.0, 542.0); const Rect snackBarRect = Rect.fromLTRB(12.0, 494.0, 60.0, 542.0);
await _runDockedTests( await _runDockedTests(
...@@ -1306,9 +1306,9 @@ void main() { ...@@ -1306,9 +1306,9 @@ void main() {
testWidgets('centerDocked', (WidgetTester tester) async { testWidgets('centerDocked', (WidgetTester tester) async {
const Rect defaultRect = Rect.fromLTRB(372.0, 494.0, 428.0, 550.0); const Rect defaultRect = Rect.fromLTRB(372.0, 494.0, 428.0, 550.0);
// Positioned relative to BottomNavigationBar // Positioned relative to BottomNavigationBar
const Rect bottomNavigationBarRect = Rect.fromLTRB(372.0, 473.0, 428.0, 529.0); const Rect bottomNavigationBarRect = Rect.fromLTRB(372.0, 466.0, 428.0, 522.0);
// Positioned relative to BottomNavigationBar & BottomSheet // Positioned relative to BottomNavigationBar & BottomSheet
const Rect bottomSheetRect = Rect.fromLTRB(372.0, 373.0, 428.0, 429.0); const Rect bottomSheetRect = Rect.fromLTRB(372.0, 366.0, 428.0, 422.0);
// Positioned relative to SnackBar // Positioned relative to SnackBar
const Rect snackBarRect = Rect.fromLTRB(372.0, 486.0, 428.0, 542.0); const Rect snackBarRect = Rect.fromLTRB(372.0, 486.0, 428.0, 542.0);
await _runDockedTests( await _runDockedTests(
...@@ -1324,9 +1324,9 @@ void main() { ...@@ -1324,9 +1324,9 @@ void main() {
testWidgets('miniCenterDocked', (WidgetTester tester) async { testWidgets('miniCenterDocked', (WidgetTester tester) async {
const Rect defaultRect = Rect.fromLTRB(376.0, 502.0, 424.0, 550.0); const Rect defaultRect = Rect.fromLTRB(376.0, 502.0, 424.0, 550.0);
// Positioned relative to BottomNavigationBar // Positioned relative to BottomNavigationBar
const Rect bottomNavigationBarRect = Rect.fromLTRB(376.0, 477.0, 424.0, 525.0); const Rect bottomNavigationBarRect = Rect.fromLTRB(376.0, 470.0, 424.0, 518.0);
// Positioned relative to BottomNavigationBar & BottomSheet // Positioned relative to BottomNavigationBar & BottomSheet
const Rect bottomSheetRect = Rect.fromLTRB(376.0, 377.0, 424.0, 425.0); const Rect bottomSheetRect = Rect.fromLTRB(376.0, 370.0, 424.0, 418.0);
// Positioned relative to SnackBar // Positioned relative to SnackBar
const Rect snackBarRect = Rect.fromLTRB(376.0, 494.0, 424.0, 542.0); const Rect snackBarRect = Rect.fromLTRB(376.0, 494.0, 424.0, 542.0);
await _runDockedTests( await _runDockedTests(
...@@ -1343,9 +1343,9 @@ void main() { ...@@ -1343,9 +1343,9 @@ void main() {
testWidgets('endDocked', (WidgetTester tester) async { testWidgets('endDocked', (WidgetTester tester) async {
const Rect defaultRect = Rect.fromLTRB(728.0, 494.0, 784.0, 550.0); const Rect defaultRect = Rect.fromLTRB(728.0, 494.0, 784.0, 550.0);
// Positioned relative to BottomNavigationBar // Positioned relative to BottomNavigationBar
const Rect bottomNavigationBarRect = Rect.fromLTRB(728.0, 473.0, 784.0, 529.0); const Rect bottomNavigationBarRect = Rect.fromLTRB(728.0, 466.0, 784.0, 522.0);
// Positioned relative to BottomNavigationBar & BottomSheet // Positioned relative to BottomNavigationBar & BottomSheet
const Rect bottomSheetRect = Rect.fromLTRB(728.0, 373.0, 784.0, 429.0); const Rect bottomSheetRect = Rect.fromLTRB(728.0, 366.0, 784.0, 422.0);
// Positioned relative to SnackBar // Positioned relative to SnackBar
const Rect snackBarRect = Rect.fromLTRB(728.0, 486.0, 784.0, 542.0); const Rect snackBarRect = Rect.fromLTRB(728.0, 486.0, 784.0, 542.0);
await _runDockedTests( await _runDockedTests(
...@@ -1361,9 +1361,9 @@ void main() { ...@@ -1361,9 +1361,9 @@ void main() {
testWidgets('miniEndDocked', (WidgetTester tester) async { testWidgets('miniEndDocked', (WidgetTester tester) async {
const Rect defaultRect = Rect.fromLTRB(740.0, 502.0, 788.0, 550.0); const Rect defaultRect = Rect.fromLTRB(740.0, 502.0, 788.0, 550.0);
// Positioned relative to BottomNavigationBar // Positioned relative to BottomNavigationBar
const Rect bottomNavigationBarRect = Rect.fromLTRB(740.0, 477.0, 788.0, 525.0); const Rect bottomNavigationBarRect = Rect.fromLTRB(740.0, 470.0, 788.0, 518.0);
// Positioned relative to BottomNavigationBar & BottomSheet // Positioned relative to BottomNavigationBar & BottomSheet
const Rect bottomSheetRect = Rect.fromLTRB(740.0, 377.0, 788.0, 425.0); const Rect bottomSheetRect = Rect.fromLTRB(740.0, 370.0, 788.0, 418.0);
// Positioned relative to SnackBar // Positioned relative to SnackBar
const Rect snackBarRect = Rect.fromLTRB(740.0, 494.0, 788.0, 542.0); const Rect snackBarRect = Rect.fromLTRB(740.0, 494.0, 788.0, 542.0);
await _runDockedTests( await _runDockedTests(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment