This commit is contained in:
2023-02-25 19:29:10 -05:00
parent ca3b497fba
commit 81f6cf5b1f
6 changed files with 151 additions and 180 deletions

View File

@@ -1,72 +1,94 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:ruswipeshare/main.dart';
import 'package:flutter/material.dart';
import 'package:persistent_bottom_nav_bar/persistent_tab_view.dart';
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
import 'main_screen.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({ Key? key }) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('FlutterFire UI'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('You are logged in!'),
ElevatedButton(
onPressed: () {
FirebaseAuth.instance.signOut();
},
child: const Text('Sign out'),
),
],
),
),
bottomNavigationBar: MyNavBar(),
);
}
_HomeScreenState createState() => _HomeScreenState();
}
// class _HomeScreenState extends State<HomeScreen> {
// int _selectedIndex = 0;
class _HomeScreenState extends State<HomeScreen> {
late PersistentTabController _controller;
@override
void initState() {
super.initState();
_controller = PersistentTabController();
}
List<Widget> _buildScreens() => [
const MainScreen(),
const MainScreen(),
const MainScreen(),
const MainScreen(),
];
// void _onItemTapped(int index) {
// if (_selectedIndex == index) return;
// setState(() {
// _selectedIndex = index;
// });
// Navigator.push(
// context,
// MaterialPageRoute(builder: (context) => pages.elementAt(index)),
// );
// }
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// appBar: AppBar(
// title: const Text('FlutterFire UI'),
// ),
// body: Center(
// child: Column(
// mainAxisAlignment: MainAxisAlignment.center,
// children: [
// const Text('You are logged in!'),
// ElevatedButton(
// onPressed: () {
// FirebaseAuth.instance.signOut();
// },
// child: const Text('Sign out'),
// ),
// ],
// ),
// ),
// bottomNavigationBar: const MyNavBar(),
// );
// }
// }
List<PersistentBottomNavBarItem> _navBarsItems() => [
PersistentBottomNavBarItem(
icon: const Icon(Icons.shopping_cart),
title: "Buy",
activeColorPrimary: Colors.blue,
inactiveColorPrimary: Colors.grey,
inactiveColorSecondary: Colors.purple),
PersistentBottomNavBarItem(
icon: const Icon(Icons.attach_money),
title: "Sell",
activeColorPrimary: Colors.teal,
inactiveColorPrimary: Colors.grey,
routeAndNavigatorSettings: const RouteAndNavigatorSettings(
initialRoute: "/",
),
),
PersistentBottomNavBarItem(
icon: const Icon(Icons.person),
title: "Profile",
activeColorPrimary: Colors.blueAccent,
inactiveColorPrimary: Colors.grey,
routeAndNavigatorSettings: const RouteAndNavigatorSettings(
initialRoute: "/",
),
),
PersistentBottomNavBarItem(
icon: const Icon(Icons.settings),
title: "Settings",
activeColorPrimary: Colors.indigo,
inactiveColorPrimary: Colors.grey,
routeAndNavigatorSettings: const RouteAndNavigatorSettings(
initialRoute: "/",
),
),
];
@override
Widget build(BuildContext context) {
return PersistentTabView(
context,
controller: _controller,
screens: _buildScreens(),
items: _navBarsItems(),
confineInSafeArea: true,
backgroundColor: Colors.white, // Default is Colors.white.
handleAndroidBackButtonPress: true, // Default is true.
resizeToAvoidBottomInset: true, // This needs to be true if you want to move up the screen when keyboard appears. Default is true.
stateManagement: true, // Default is true.
hideNavigationBarWhenKeyboardShows: true, // Recommended to set 'resizeToAvoidBottomInset' as true while using this argument. Default is true.
decoration: NavBarDecoration(
borderRadius: BorderRadius.circular(10.0),
colorBehindNavBar: Colors.white,
),
popAllScreensOnTapOfSelectedTab: true,
popActionScreens: PopActionScreensType.all,
itemAnimationProperties: const ItemAnimationProperties( // Navigation Bar's items animation properties.
duration: Duration(milliseconds: 200),
curve: Curves.ease,
),
screenTransitionAnimation: const ScreenTransitionAnimation( // Screen transition animation on change of selected tab.
animateTabTransition: true,
curve: Curves.ease,
duration: Duration(milliseconds: 200),
),
navBarStyle: NavBarStyle.style13, // Choose the nav bar style with this property.
);
}
}