Unverified Commit f1c8723a authored by Matheus Kirchesch's avatar Matheus Kirchesch Committed by GitHub

Added option to disable [NavigationRailDestination]s (#127113)

parent a6ef86a8
......@@ -467,6 +467,7 @@ class _NavigationRailState extends State<NavigationRail> with TickerProviderStat
tabIndex: i + 1,
tabCount: widget.destinations.length,
),
disabled: widget.destinations[i].disabled,
),
if (widget.trailing != null)
widget.trailing!,
......@@ -545,6 +546,7 @@ class _RailDestination extends StatelessWidget {
required this.useIndicator,
this.indicatorColor,
this.indicatorShape,
this.disabled = false,
}) : _positionAnimation = CurvedAnimation(
parent: ReverseAnimation(destinationAnimation),
curve: Curves.easeInOut,
......@@ -567,6 +569,7 @@ class _RailDestination extends StatelessWidget {
final bool useIndicator;
final Color? indicatorColor;
final ShapeBorder? indicatorShape;
final bool disabled;
final Animation<double> _positionAnimation;
......@@ -577,12 +580,16 @@ class _RailDestination extends StatelessWidget {
'[NavigationRail.indicatorColor] does not have an effect when [NavigationRail.useIndicator] is false',
);
final bool material3 = Theme.of(context).useMaterial3;
final ThemeData theme = Theme.of(context);
final bool material3 = theme.useMaterial3;
final EdgeInsets destinationPadding = (padding ?? EdgeInsets.zero).resolve(Directionality.of(context));
Offset indicatorOffset;
final Widget themedIcon = IconTheme(
data: iconTheme,
data: disabled
? iconTheme.copyWith(color: theme.colorScheme.onSurface.withOpacity(0.38))
: iconTheme,
child: icon,
);
final Widget styledLabel = DefaultTextStyle(
......@@ -761,7 +768,7 @@ class _RailDestination extends StatelessWidget {
Material(
type: MaterialType.transparency,
child: _IndicatorInkWell(
onTap: onTap,
onTap: disabled ? null : onTap,
borderRadius: BorderRadius.all(Radius.circular(minWidth / 2.0)),
customBorder: indicatorShape,
splashColor: colors.primary.withOpacity(0.12),
......@@ -909,6 +916,7 @@ class NavigationRailDestination {
this.indicatorShape,
required this.label,
this.padding,
this.disabled = false,
}) : selectedIcon = selectedIcon ?? icon;
/// The icon of the destination.
......@@ -954,6 +962,9 @@ class NavigationRailDestination {
/// The amount of space to inset the destination item.
final EdgeInsetsGeometry? padding;
/// Indicates that this destination is inaccessible.
final bool disabled;
}
class _ExtendedNavigationRailAnimation extends InheritedWidget {
......
......@@ -3136,6 +3136,50 @@ void main() {
expect(_getIndicatorDecoration(tester)?.shape, shape);
});
testWidgets("Destination's respect their disabled state", (WidgetTester tester) async {
late int selectedIndex;
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.star_border),
selectedIcon: Icon(Icons.star),
label: Text('Bcd'),
),
NavigationRailDestination(
icon: Icon(Icons.bookmark_border),
selectedIcon: Icon(Icons.bookmark),
label: Text('Cde'),
disabled: true,
),
],
onDestinationSelected: (int index) {
selectedIndex = index;
},
labelType: NavigationRailLabelType.all,
),
);
await tester.tap(find.text('Abc'));
expect(selectedIndex, 0);
await tester.tap(find.text('Bcd'));
expect(selectedIndex, 1);
await tester.tap(find.text('Cde'));
expect(selectedIndex, 1);
// Wait for any pending shader compilation.
tester.pumpAndSettle();
});
group('Material 2', () {
// These tests are only relevant for Material 2. Once Material 2
// support is deprecated and the APIs are removed, these tests
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment