Added null check before NavigationRail.onDestinationSelected is called (#78032)
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user