Written by Anonymous
import 'package:flutter/material.dart';
import 'home_page.dart';
class BottomBar extends StatefulWidget {
const BottomBar({super.key});
@override
State<BottomBar> createState() => _BottomBarState();
}
class _BottomBarState extends State<BottomBar> {
int _selectedIndex = 0;
// List of widget screens to be displayed based on the selected index
static const List<Widget> _widgetOptions = <Widget>[
HomePage(),
Text('Search Screen'),
Text('Profile Screen'),
];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
label: 'Search',
),
BottomNavigationBarItem(
icon: Icon(Icons.account_circle),
label: 'Profile',
),
],
currentIndex: _selectedIndex,
onTap: _onItemTapped,
),
);
}
}
HOme PAge
import 'package:flutter/material.dart';
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("HOME PAGE"),
),
body: const Column(
children: [
Text("Sdasds"),
Text("Sdasds"),
Text("Sdasds"),
Text("Sdasds"),
Text("Sdasds"),
],
),
);
}
}
Main FIle COde
import 'package:flutter/material.dart';
import 'pages/bottom_bar.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
// Created By Yaqoob Developer,
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const BottomBar(),
);
}
}