Flutter UI Widgets

Nov 9 2021 · Dart 2.14, Flutter 2.5, VS Code 1.61

Part 1: Flutter UI Widgets

06. Work with BottomNavigationBar

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 05. Create Scrollable Contents Next episode: 07. Use the FutureBuilder Widget

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 06. Work with BottomNavigationBar

If you’re using Flutter 1.17 and above then you won’t get the Dart constraint error since those versions work a newer Dart sdk.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Tabs are very common is most modern apps and Flutter provides us with different tab based widgets. The Scaffold widget provides us with the BottomNavigationBar which let’s us add a widget that can be shown at the bottom of the screen. Let’s add a BottomNavigationBar widget. Paste the following code inside the Scaffold:

...
bottomNavigationBar: BottomNavigationBar(
  currentIndex: 0,
  onTap: (int index) {},
  items: [
    const BottomNavigationBarItem(
      label: 'Home',
      icon: Icon(Icons.home),
    ),
    const BottomNavigationBarItem(
      label: 'Inbox',
      icon: Icon(Icons.mail),
    ),
  ],
),
...
...
// Members
final List<Widget> _pages = [
  const HomePage(),
  const InboxPage(),
];

int _selectedIndex = 0;
...

// Scaffold
body: IndexedStack(
  index: _selectedIndex,
  children: <Widget>[..._pages],
),
...

// BottomNavigationBar
currentIndex: _selectedIndex,
_onTapped(int index) {
  setState(() {
    _selectedIndex = index;
  });
}
...
onTap: _onTapped,
...