I am trying to add a new screen in my flutter app however if the navigation bar has more than three destinations I get this error:
package:flutter/src/material/navigation_bar.dart': Failed assertion: line 117 pos 15: '0 <= selectedIndex && selectedIndex < destinations.length': is not true.
I have a temporary fix by just modifying the navigation.dart file of flutter but when it comes to production that may not be good.
is there anything else I could do?
here is my code for reference:
return Scaffold(
backgroundColor: Palette.backgroundColor,
bottomNavigationBar: NavigationBar(
height: MediaQuery.of(context).size.width * 0.18,
onDestinationSelected: (int index) {
setState(() {
currentPageIndex = index;
});
},
backgroundColor: Colors.white,
indicatorColor: Palette.iconBackground,
selectedIndex: currentPageIndex,
destinations: <Widget>[
NavigationDestination(
// home
selectedIcon: Icon(Icons.home),
icon: Icon(Icons.home_outlined),
label: 'Home',
),
// paymemts/notifications
NavigationDestination(
selectedIcon: Icon(Icons.payments),
icon: Icon(Icons.payments_outlined),
label: 'Payments',
),
NavigationDestination(
selectedIcon: Icon(Icons.payments),
icon: Icon(Icons.payments_outlined),
label: 'test',
),
// profile
NavigationDestination(
selectedIcon: Icon(Icons.person),
icon: Icon(Icons.person_outline),
label: 'Profile',
)
]),
//body to store outstanding balance and sis nav cards
body: IndexedStack(
index: currentPageIndex,
children: [
DashboardScreen(
name: GetProfileData.displayName(name),
email: email,
),
const NotifPage(),
const ComingSoonPage(),
const ProfileScreen(),
],
),
);