From 2867b31f5ed4ab45d2697cda0fd4281c62e64220 Mon Sep 17 00:00:00 2001 From: Matheus Kirchesch Date: Thu, 7 Sep 2023 14:21:52 -0300 Subject: [PATCH] Fixed [NavigationRailDestination]'s label opacity while disabled not being coherent with the icon (#132345) Fixing the opacity of the NavigationRailDestination widget label while it is disabled, right now it doesn't get affected by the disabled attribute, which doesn't match the icon that gets affected * https://github.com/flutter/flutter/issues/132344 I believe this PR should be marked as [test-exempt] ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. --- .../lib/src/material/navigation_rail.dart | 4 +- .../test/material/navigation_rail_test.dart | 41 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/navigation_rail.dart b/packages/flutter/lib/src/material/navigation_rail.dart index 4219d52d302a..6b7228f5cf78 100644 --- a/packages/flutter/lib/src/material/navigation_rail.dart +++ b/packages/flutter/lib/src/material/navigation_rail.dart @@ -594,7 +594,9 @@ class _RailDestination extends StatelessWidget { child: icon, ); final Widget styledLabel = DefaultTextStyle( - style: labelTextStyle, + style: disabled + ? labelTextStyle.copyWith(color: theme.colorScheme.onSurface.withOpacity(0.38)) + : labelTextStyle, child: label, ); diff --git a/packages/flutter/test/material/navigation_rail_test.dart b/packages/flutter/test/material/navigation_rail_test.dart index b94dc6519465..ae0b4571747f 100644 --- a/packages/flutter/test/material/navigation_rail_test.dart +++ b/packages/flutter/test/material/navigation_rail_test.dart @@ -3290,6 +3290,47 @@ void main() { tester.pumpAndSettle(); }); + testWidgetsWithLeakTracking("Destination's label with the right opacity while disabled", (WidgetTester tester) async { + await _pumpNavigationRail( + tester, + navigationRail: NavigationRail( + selectedIndex: 0, + destinations: const [ + NavigationRailDestination( + icon: Icon(Icons.favorite_border), + selectedIcon: Icon(Icons.favorite), + label: Text('Abc'), + ), + NavigationRailDestination( + icon: Icon(Icons.bookmark_border), + selectedIcon: Icon(Icons.bookmark), + label: Text('Bcd'), + disabled: true, + ), + ], + onDestinationSelected: (int index) {}, + labelType: NavigationRailLabelType.all, + ), + ); + + await tester.pumpAndSettle(); + + double? defaultTextStyleOpacity(String text) { + return tester.widget( + find.ancestor( + of: find.text(text), + matching: find.byType(DefaultTextStyle), + ).first, + ).style.color?.opacity; + } + + final double? abcLabelOpacity = defaultTextStyleOpacity('Abc'); + final double? bcdLabelOpacity = defaultTextStyleOpacity('Bcd'); + + expect(abcLabelOpacity, 1.0); + expect(bcdLabelOpacity, closeTo(0.38, 0.01)); + }); + group('Material 2', () { // These tests are only relevant for Material 2. Once Material 2 // support is deprecated and the APIs are removed, these tests