diff --git a/packages/flutter/lib/src/material/bottom_navigation_bar.dart b/packages/flutter/lib/src/material/bottom_navigation_bar.dart index dd4f4f0407..3e57788995 100644 --- a/packages/flutter/lib/src/material/bottom_navigation_bar.dart +++ b/packages/flutter/lib/src/material/bottom_navigation_bar.dart @@ -647,7 +647,14 @@ class _Tile extends StatelessWidget { heightFactor: 1, child: Row( mainAxisSize: MainAxisSize.min, - children: [icon, const SizedBox(width: 8), label], + children: [ + icon, + const SizedBox(width: 8), + // Flexible lets the overflow property of + // label to work and IntrinsicWidth gives label a + // resonable width preventing extra space before it. + Flexible(child: IntrinsicWidth(child: label)) + ], ), ); } diff --git a/packages/flutter/test/material/bottom_navigation_bar_test.dart b/packages/flutter/test/material/bottom_navigation_bar_test.dart index c724bba3ca..568c1b0e86 100644 --- a/packages/flutter/test/material/bottom_navigation_bar_test.dart +++ b/packages/flutter/test/material/bottom_navigation_bar_test.dart @@ -3122,6 +3122,59 @@ void main() { expect(tester.getRect(find.byKey(icon0)), Rect.fromLTRB(firstItemLeft, iconTop, firstItemLeft + iconWidth, iconTop + iconHeight)); expect(tester.getRect(find.byKey(icon1)), Rect.fromLTRB(secondItemLeft, iconTop, secondItemLeft + iconWidth, iconTop + iconHeight)); }, skip: kIsWeb && !isCanvasKit); // https://github.com/flutter/flutter/issues/99933 + + testWidgets('BottomNavigationBar linear landscape layout label RenderFlex overflow',(WidgetTester tester) async { + //Regression test for https://github.com/flutter/flutter/issues/112163 + + tester.view.physicalSize = const Size(540, 340); + + await tester.pumpWidget( + MaterialApp( + home: Builder( + builder: (BuildContext context) { + return Scaffold( + bottomNavigationBar: BottomNavigationBar( + type: BottomNavigationBarType.fixed, + landscapeLayout: BottomNavigationBarLandscapeLayout.linear, + items: const [ + BottomNavigationBarItem( + icon: Icon(Icons.home_rounded), + label: 'Home Challenges', + backgroundColor: Colors.grey, + tooltip: '', + ), + BottomNavigationBarItem( + icon: Icon(Icons.date_range_rounded), + label: 'Daily Challenges', + backgroundColor: Colors.grey, + tooltip: '', + ), + BottomNavigationBarItem( + icon: Icon(Icons.wind_power), + label: 'Awards Challenges', + backgroundColor: Colors.grey, + tooltip: '', + ), + BottomNavigationBarItem( + icon: Icon(Icons.bar_chart_rounded), + label: 'Statistics Challenges', + backgroundColor: Colors.grey, + tooltip: '', + ), + ], + )); + }, + ), + ), + ); + + await expectLater( + find.byType(MaterialApp), + matchesGoldenFile('bottom_navigation_bar.label_overflow.png'), + ); + + addTearDown(tester.view.resetPhysicalSize); + }); } Widget boilerplate({ Widget? bottomNavigationBar, required TextDirection textDirection, bool? useMaterial3 }) {