Flutter / UI Elements / BaseBottomNavBar
BaseBottomNavBar
-
Usage
to implement a bottom navigation bar with different screens/pages in Flutter, you can create a structure where each bottom navigation item corresponds to a different screen.
import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: BaseBottomNavBar(), ); } } class BaseBottomNavBar extends StatefulWidget { @override _BaseBottomNavBarState createState() => _BaseBottomNavBarState(); } class _BaseBottomNavBarState extends State { int _currentIndex = 0; final List _screens = [ ScreenOne(), ScreenTwo(), ScreenThree(), ]; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Bottom Navigation Bar Example'), ), body: _screens[_currentIndex], bottomNavigationBar: BottomNavigationBar( currentIndex: _currentIndex, onTap: (index) { setState(() { _currentIndex = index; }); }, items: [ BottomNavigationBarItem( icon: Icon(Icons.home), label: 'Screen 1', ), BottomNavigationBarItem( icon: Icon(Icons.favorite), label: 'Screen 2', ), BottomNavigationBarItem( icon: Icon(Icons.person), label: 'Screen 3', ), ], ), ); } } class ScreenOne extends StatelessWidget { @override Widget build(BuildContext context) { return Container( color: Colors.blue, child: Center( child: Text('Screen 1'), ), ); } } class ScreenTwo extends StatelessWidget { @override Widget build(BuildContext context) { return Container( color: Colors.red, child: Center( child: Text('Screen 2'), ), ); } } class ScreenThree extends StatelessWidget { @override Widget build(BuildContext context) { return Container( color: Colors.green, child: Center( child: Text('Screen 3'), ), ); } }