Here is my code. It is successfully changing screens but the active tab is not changing. Any help? I would like that if the for example it click on profile it will automatically show that the profile tab is active.
class BottomNavBar extends StatefulWidget {
const BottomNavBar({super.key});
@override
_BottomNavBarState createState() => _BottomNavBarState();
}
class _BottomNavBarState extends State<BottomNavBar> {
int _selectedIndex = 0;
static final List<String> _routeNames = [
'/home',
'/booking',
'/settings',
'/profile'
];
... designs in omy code and Gnav Widget
Gnav(tabs: const [
GButton(
icon: LineIcons.home,
text: 'Home',
),
GButton(
icon: LineIcons.bookOpen,
text: 'Bookings',
),
GButton(
icon: LineIcons.cog,
text: 'Settings',
),
GButton(
icon: LineIcons.user,
text: 'Profile',
),
],)
selectedIndex: _selectedIndex,
onTabChange: (index) {
setState(() {
selectedIndex = index;
final goRouter = GoRouter.of(context);
goRouter.push(_routeNames[index]);
});
},