Unverified Commit 44ba6ab0 authored by Wilson Wilson's avatar Wilson Wilson Committed by GitHub

Added null check before NavigationRail.onDestinationSelected is called (#78032)

parent 4465f688
......@@ -498,7 +498,8 @@ class _NavigationRailState extends State<NavigationRail> with TickerProviderStat
labelTextStyle: widget.selectedIndex == i ? selectedLabelTextStyle : unselectedLabelTextStyle,
padding: widget.destinations[i].padding,
onTap: () {
widget.onDestinationSelected!(i);
if (widget.onDestinationSelected != null)
widget.onDestinationSelected!(i);
},
indexLabel: localizations.tabLabel(
tabIndex: i + 1,
......
......@@ -1918,6 +1918,21 @@ void main() {
expect(selectedIndex, 2);
});
testWidgets('onDestinationSelected is not called if null', (WidgetTester tester) async {
const int selectedIndex = 0;
await _pumpNavigationRail(
tester,
navigationRail: NavigationRail(
selectedIndex: selectedIndex,
destinations: _destinations(),
labelType: NavigationRailLabelType.all,
),
);
await tester.tap(find.text('Def'));
expect(selectedIndex, 0);
});
testWidgets('Changing destinations animate when [labelType]=selected', (WidgetTester tester) async {
int selectedIndex = 0;
......
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