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