Skip to content

Commit

Permalink
Fixed [NavigationRailDestination]'s label opacity while disabled not …
Browse files Browse the repository at this point in the history
…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

* flutter/flutter#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.
  • Loading branch information
matheus-kirchesch authored Sep 7, 2023
1 parent 6ddb3b0 commit 2867b31
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/flutter/lib/src/material/navigation_rail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down
41 changes: 41 additions & 0 deletions packages/flutter/test/material/navigation_rail_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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>[
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<DefaultTextStyle>(
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
Expand Down

0 comments on commit 2867b31

Please sign in to comment.