From 4d6c00cc2b9942f25b93d8f6820bd9fbc84de575 Mon Sep 17 00:00:00 2001 From: Aliasgar Vohra <38110731+aliasgar4558@users.noreply.github.com> Date: Wed, 8 May 2024 16:35:24 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20:=20FIX=20:=20Long=20labels=20ov?= =?UTF-8?q?erflowing=20in=20extended=20navigation=20rail.=20(#145474)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It has been observed that while in extended navigation rail, if longer labels are given the it is overflowing. Problem identified in "NavigationRail" widget only in case of extended version of it. This PR includes the fix for the same. Fixes https://github.com/flutter/flutter/issues/110901. *NO breaking changes.* --- .../lib/src/material/navigation_rail.dart | 19 ++++--- .../test/material/navigation_rail_test.dart | 50 +++++++++++++++++++ 2 files changed, 61 insertions(+), 8 deletions(-) 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