How to use image icon (from assets) instead of IconData and pagination bottomNavigationBar in Flutter
Here's how you can use an icon from assets
ImageIcon(
AssetImage("images/icon_more.png"),
color: Color(0xFF3A5A98),
),
Try this example for BottomNavBar click
So there what you want to replace is BottomNavigationBarItem
new BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
to
new BottomNavigationBarItem(
icon: ImageIcon(
AssetImage("images/icon_more.png"),
color: Color(0xFF3A5A98),
),
title: Text('Home'),
),
You can learn about the navigation from the article I shared
UPDATE Here's an example as you requested.
So here the _children variable holds the list of pages that you want to navigate based on the selection of BottomNavBarItem.
How we navigate is when we press a tab item we set it's index using onTabTapped function.. When the index change the view is changed accordingly as we have instructed the body show the current index of the children
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _currentIndex = 0;
final List<Widget> _children = [
Container(
color: Colors.red,
),
Container(
color: Colors.blue,
),
Container(
color: Colors.green,
)
];
void onTabTapped(int index) {
setState(() {
_currentIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: _children[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
onTap: onTabTapped, // new
currentIndex: _currentIndex, // new
items: [
new BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
new BottomNavigationBarItem(
icon: Icon(Icons.mail),
title: Text('Messages'),
),
new BottomNavigationBarItem(
icon: Icon(Icons.person), title: Text('Profile'))
],
),
);
}
}