I am using BottomNavigationBar
and when clicked on any icons in the navigation bar. I want it to go to next screen. That's why I am using named route here.
main.dart
code
import 'package:flutter/material.dart';
import 'Screens/profilePage1/profilePage1.dart';
void main() => runApp(MyStatefulWidget());
class MyStatefulWidget extends StatefulWidget {
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
int _selectedIndex = 0;
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
routes: {
// When navigating to the "/" route, build the FirstScreen widget.
'/first': (context) => ProfilePage1(),
// When navigating to the "/second" route, build the SecondScreen widget.
'/second': (context) => ProfilePage1(),
'/third': (context) => ProfilePage1(),
'/fourth': (context) => ProfilePage1(),
'/fifth': (context) => ProfilePage1(),
},
home: Scaffold(
body: Center(
child: routes.elementAt(_selectedIndex),
),
bottomNavigationBar: BottomNavigationBar(
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(icon: Icon(Icons.home), title: Text("")),
BottomNavigationBarItem(
icon: Icon(Icons.calendar_today), title: Text("")),
BottomNavigationBarItem(
icon: Icon(
Icons.account_circle,
size: 35,
color: Color(0xFF334192),
),
title: Text("")),
BottomNavigationBarItem(icon: Icon(Icons.message), title: Text("")),
BottomNavigationBarItem(
icon: Icon(Icons.table_chart), title: Text("")),
],
currentIndex: _selectedIndex,
selectedItemColor: Color(0xFF334192),
unselectedItemColor: Colors.grey,
onTap: (index){
},
),
),
);
}
}
Here I have created 5 named routes. And I want it to pass to body when particular tab is clicked. How do I do that?