Taxi Booking in flutter - BottomNavigationBar dart file
Create a dart file named as 'bottomnavigationbar.dart' in lib -> common folder. It will create bottom menu
Please, support my blog by clicking on our sponsors ad!
import 'package:flutter/material.dart';
import 'package:myfirstproject/Dashboard.dart';
import 'constants.dart';
class CommonBottomNavigationBar extends StatefulWidget {
const CommonBottomNavigationBar({super.key, required this.pages});
final List<Widget> pages;
@override
State<CommonBottomNavigationBar> createState() =>
_CommonBottomNavigationBarState();
}
class _CommonBottomNavigationBarState
extends State<CommonBottomNavigationBar> {
int _selectedIndex = 0;
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.camera_rounded),
label: 'Promo',
),
BottomNavigationBarItem(
icon: Icon(Icons.list_alt),
label: 'Order',
),
BottomNavigationBarItem(
icon: Icon(Icons.inbox_rounded),
label: 'Inbox',
),
],
currentIndex: _selectedIndex,
selectedItemColor: Navy,
unselectedItemColor: RegentGray,
onTap: _onItemTapped,
);
}
}
class CommonWrapper extends StatelessWidget {
final Widget currentContent;
CommonWrapper({required this.currentContent});
@override
Widget build(BuildContext context) {
return CommonLayout(
pages: [
Dashboard(),
Dashboard(),
Dashboard(),
Dashboard(),
],
currentContent: currentContent,
);
}
}
class CommonLayout extends StatelessWidget {
final List<Widget> pages;
final Widget currentContent;
CommonLayout({required this.pages, required this.currentContent});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: SecondaryColor,
body: currentContent,
bottomNavigationBar: CommonBottomNavigationBar(pages: pages),
);
}
}
Comments
Post a Comment