diff --git a/packages/flutter/lib/src/material/navigation_rail.dart b/packages/flutter/lib/src/material/navigation_rail.dart index 731b470a95..c71df7d45d 100644 --- a/packages/flutter/lib/src/material/navigation_rail.dart +++ b/packages/flutter/lib/src/material/navigation_rail.dart @@ -698,16 +698,19 @@ class _RailDestinationState extends State<_RailDestination> { ), child: ClipRect( child: Row( + mainAxisSize: MainAxisSize.min, children: [ iconPart, - Align( - heightFactor: 1.0, - widthFactor: widget.extendedTransitionAnimation.value, - alignment: AlignmentDirectional.centerStart, - child: FadeTransition( - alwaysIncludeSemantics: true, - opacity: labelFadeAnimation, - child: styledLabel, + Flexible( + child: Align( + heightFactor: 1.0, + widthFactor: widget.extendedTransitionAnimation.value, + alignment: AlignmentDirectional.centerStart, + child: FadeTransition( + alwaysIncludeSemantics: true, + opacity: labelFadeAnimation, + child: styledLabel, + ), ), ), SizedBox(width: _horizontalDestinationPadding * widget.extendedTransitionAnimation.value), diff --git a/packages/flutter/test/material/navigation_rail_test.dart b/packages/flutter/test/material/navigation_rail_test.dart index 3f4f3947e5..de70ed5f7a 100644 --- a/packages/flutter/test/material/navigation_rail_test.dart +++ b/packages/flutter/test/material/navigation_rail_test.dart @@ -7,6 +7,7 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; + import '../widgets/semantics_tester.dart'; void main() { @@ -3631,6 +3632,55 @@ void main() { expect(tester.takeException(), isNull); }); + testWidgets('NavigationRail labels shall not overflow if longer texts provided - extended', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/110901. + // The navigation rail has a narrow width constraint. The text should wrap. + const String normalLabel = 'Abc'; + const String longLabel = 'Very long bookmark text for navigation destination'; + await tester.pumpWidget(MaterialApp( + home: Builder( + builder: (BuildContext context) { + return Scaffold( + body: Row( + children: [ + SizedBox( + width: 140.0, + child: NavigationRail( + selectedIndex: 1, + extended: true, + destinations: const [ + NavigationRailDestination( + icon: Icon(Icons.favorite_border), + selectedIcon: Icon(Icons.favorite), + label: Text(normalLabel), + ), + NavigationRailDestination( + icon: Icon(Icons.bookmark_border), + selectedIcon: Icon(Icons.bookmark), + label: Text(longLabel), + ), + ], + ), + ), + const Expanded( + child: Text('body'), + ), + ], + ), + ); + }, + ), + )); + + expect(find.byType(NavigationRail), findsOneWidget); + expect(find.text(normalLabel), findsOneWidget); + expect(find.text(longLabel), findsOneWidget); + + // If the widget manages to layout without throwing an overflow exception, + // the test passes. + expect(tester.takeException(), isNull); + }); + group('Material 2', () { // These tests are only relevant for Material 2. Once Material 2 // support is deprecated and the APIs are removed, these tests