Bottom Tab Bar Navigation with FAB Button

 import "package:bloc_state_management/Bottom_Tab_Bar_Navigation/Pages/chat.dart";

import "package:bloc_state_management/Bottom_Tab_Bar_Navigation/Pages/dashboard.dart";
import "package:bloc_state_management/Bottom_Tab_Bar_Navigation/Pages/profile.dart";
import "package:bloc_state_management/Bottom_Tab_Bar_Navigation/Pages/setting.dart";
import "package:flutter/material.dart";

void main()
{
runApp(const MyApp());
}
class MyApp extends StatelessWidget
{
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "HomePage",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.grey,
),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget
{
const HomePage({super.key});

@override
State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
int currentTab = 0;

final List<Widget> screens = [
const Dashboard(),
const Chat(),
const Profile(),
const Setting(),
];

final PageStorageBucket bucket = PageStorageBucket();

Widget currentScreen = const Dashboard();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("HomePage"),
centerTitle: true,
backgroundColor: Colors.grey,
),
body: PageStorage(
bucket: bucket,
child: currentScreen,
),
floatingActionButton: FloatingActionButton(
onPressed: () {},
backgroundColor: Colors.blue,
shape: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0),
),
child: const Icon(Icons.add, color: Colors.white, size: 30.0),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: BottomAppBar(
shape: const CircularNotchedRectangle(),
notchMargin: 10.0,
child: Container(
height: 60.0,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
/// Left Tab bar Icons
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
MaterialButton(
minWidth: 40.0,
onPressed: () {
setState(() {
currentScreen = const Dashboard();
currentTab = 0;
},);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.dashboard,
color: currentTab == 0 ? Colors.blue : Colors.grey,
),
Text("Dashboard",
style: TextStyle(color: currentTab == 0 ? Colors.blue : Colors.grey),
),
],
),
),
const SizedBox(width: 50.0),
MaterialButton(
minWidth: 40.0,
onPressed: () {
setState(() {
currentScreen = const Chat();
currentTab = 1;
},);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.chat,
color: currentTab == 1 ? Colors.blue : Colors.grey,
),
Text("Chat",
style: TextStyle(color: currentTab == 1 ? Colors.blue : Colors.grey),
),
],
),
),
],
),


/// Right Tab bar Icons
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
MaterialButton(
minWidth: 40.0,
onPressed: () {
setState(() {
currentScreen = const Profile();
currentTab = 2;
},);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.person,
color: currentTab == 2 ? Colors.blue : Colors.grey,
),
Text("Profile",
style: TextStyle(color: currentTab == 2 ? Colors.blue : Colors.grey),
),
],
),
),
const SizedBox(width: 50.0),
MaterialButton(
minWidth: 40.0,
onPressed: () {
setState(() {
currentScreen = const Setting();
currentTab = 3;
},);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.settings,
color: currentTab == 3 ? Colors.blue : Colors.grey,
),
Text("settings",
style: TextStyle(color: currentTab == 3 ? Colors.blue : Colors.grey),
),
],
),
),
],
),
],
),
),
),
);
}
}

import "package:flutter/material.dart";

class Dashboard extends StatelessWidget {
const Dashboard({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Dashboard"),
centerTitle: true,
backgroundColor: Colors.grey,
),
body: const Center(
child: Text(
"Dashboard",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30.0),
),
),
);
}
}
import "package:flutter/material.dart";

class Chat extends StatelessWidget {
const Chat({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Chat Screen"),
centerTitle: true,
backgroundColor: Colors.grey,
),
body: const Center(
child: Text(
"Chat Screen",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30.0),
),
),
);
}
}
import "package:flutter/material.dart";

class Profile extends StatelessWidget {
const Profile({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Profile Page"),
centerTitle: true,
backgroundColor: Colors.grey,
),
body: const Center(
child: Text(
"Profile",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30.0),
),
),
);
}
}
import "package:flutter/material.dart";

class Setting extends StatelessWidget {
const Setting({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Settings"),
centerTitle: true,
backgroundColor: Colors.grey,
),
body: const Center(
child: Text(
"Settings",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30.0),
),
),
);
}
}

Comments

Popular posts from this blog

Pagination with Bloc Pattern in Flutter

Pagination First Practical in Flutter

ExpansionPanel with ExpansionPanelList with Complete Collapse Operation in Flutter