To navigate from one screen to another screen on a single page, there are many options for making navigation easy in your application for the user. Bottom Navigation Bar is one of them.
Bottom Navigation Bar always stays at the bottom of your mobile application and provides navigation between the views of the mobile application. Each Bottom Navigation bar item denotes a different sub screen or feature of an application.
You should use Bottom Navigation if you have three to five top-level navigation items of the mobile application. Otherwise, we should use Navigation Drawer and scrollable Tabbar. You can see a simple example of Drawer and Tabbar here.
To create a bottom bar based app, Flutter SDK provides us an inbuilt widget BottomNavigationBar. You have to use BottomNavigationBarItem to define item properties.
In this post, we going to explain a basic of bottom bar implementation in Flutter. We'll use three item, Home, Location, and Friends. After clicking or swipe on the screen, you'll able to change application feature.
This blog assumes that you have already set up the flutter in your PC and you have a basic idea of Flutter Application. If you have not install flutter yet, get started from here.
So, let's start it,
Creating a New Project
1. Create a new project from File ⇒ New Flutter Project with your development IDE .
2. Open main.dart file and edit it. As we have set our theme and change debug banner property of Application.
3. After that, create DashboardScreen class inside of main.dart as you can see below. We have made it stateful widget because it will update on tab change.
4. After that, create _DashboardScreenState class inside of main.dart. Here, we'll write the main logic of bottom bar navigation. So, first of all, initialize the widget with the following properties.
As you can see, we have created an instance of pageController to control navigation and we managing a tag(_page) for a page.
5. Now, create a method navigationTapped. Here, we'll change an item of the Bottom bar when the user tab on an item.
6. It's time to create the bottom bar item and set its properties. Now, edit build method. As you can see below.
in the above snippet, we have added app bar with a title Text. After that, we have provided an instance of PageView. It contains all the pages that will switch on bottom bar tap. At the end, we have used the bottomNavigationBar property for define bottom bar item.
Now merge all above code snippet, the final main.dart file look like below.
7. At the end, we have created Home, Location and Friends widget screen that we have mapped with PageView in the main.dart. As you can see, the files are the same with a different class name. In this files, we showing a title of the selected tab.
You can create some complex User Interface there and you can fetch some data from the network to display here.
As you can see it is working absolutely fine.
So that’s all for Bottom Navigation bar in Flutter. I hope the post helped you to learn about Bottom Navigation bar.
If you facing any issue, you can get a full working project from Github or please feel free to ask from comment section below.
Bottom Navigation Bar always stays at the bottom of your mobile application and provides navigation between the views of the mobile application. Each Bottom Navigation bar item denotes a different sub screen or feature of an application.
You should use Bottom Navigation if you have three to five top-level navigation items of the mobile application. Otherwise, we should use Navigation Drawer and scrollable Tabbar. You can see a simple example of Drawer and Tabbar here.
To create a bottom bar based app, Flutter SDK provides us an inbuilt widget BottomNavigationBar. You have to use BottomNavigationBarItem to define item properties.
In this post, we going to explain a basic of bottom bar implementation in Flutter. We'll use three item, Home, Location, and Friends. After clicking or swipe on the screen, you'll able to change application feature.
This blog assumes that you have already set up the flutter in your PC and you have a basic idea of Flutter Application. If you have not install flutter yet, get started from here.
So, let's start it,
Creating a New Project
1. Create a new project from File ⇒ New Flutter Project with your development IDE .
2. Open main.dart file and edit it. As we have set our theme and change debug banner property of Application.
4. After that, create _DashboardScreenState class inside of main.dart. Here, we'll write the main logic of bottom bar navigation. So, first of all, initialize the widget with the following properties.
5. Now, create a method navigationTapped. Here, we'll change an item of the Bottom bar when the user tab on an item.
6. It's time to create the bottom bar item and set its properties. Now, edit build method. As you can see below.
Now merge all above code snippet, the final main.dart file look like below.
7. At the end, we have created Home, Location and Friends widget screen that we have mapped with PageView in the main.dart. As you can see, the files are the same with a different class name. In this files, we showing a title of the selected tab.
As you can see it is working absolutely fine.
So that’s all for Bottom Navigation bar in Flutter. I hope the post helped you to learn about Bottom Navigation bar.
If you facing any issue, you can get a full working project from Github or please feel free to ask from comment section below.