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

This commit is contained in:
Wilson Wilson
2021-06-18 19:34:03 +01:00
committed by GitHub
parent 4465f68809
commit 44ba6ab099
2 changed files with 17 additions and 1 deletions

View File

@@ -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,

View File

@@ -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;