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
_HomeScreenState createState() => _HomeScreenState();
}
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(),
];
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 Scaffold(
appBar: AppBar(
title: const Text('FlutterFire UI'),
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,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('You are logged in!'),
ElevatedButton(
onPressed: () {
FirebaseAuth.instance.signOut();
},
child: const Text('Sign out'),
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),
),
),
bottomNavigationBar: MyNavBar(),
navBarStyle: NavBarStyle.style13, // Choose the nav bar style with this property.
);
}
}
// class _HomeScreenState extends State<HomeScreen> {
// int _selectedIndex = 0;
// 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(),
// );
// }
// }

View File

@@ -1,8 +1,5 @@
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_ui_auth/firebase_ui_auth.dart';
import 'package:flutter/material.dart';
import 'package:ruswipeshare/home.dart';
import 'package:ruswipeshare/sell.dart';
import 'firebase_options.dart';
import 'auth_gate.dart';
@@ -15,73 +12,38 @@ void main() async {
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
primarySwatch: CustomMaterialColor(200,61,61).mdColor,
),
home: const HomeScreen(),
home: const AuthGate(),
);
}
}
class CustomMaterialColor {
final int r;
final int g;
final int b;
class MyNavBar extends StatefulWidget {
MyNavBar({super.key});
CustomMaterialColor(this.r, this.g, this.b);
@override
State<MyNavBar> createState() => MyNavBarState();
}
class MyNavBarState extends State<MyNavBar> {
final pages = [
const SellScreen(),
const SellScreen(),
];
int _selectedIndex = 0;
void _onItemTapped(int index) {
if (runtimeType == pages.elementAt(index).runtimeType) return;
setState(() {
_selectedIndex = index;
});
Navigator.push(
context,
MaterialPageRoute(builder: (context) => pages.elementAt(index)),
);
}
@override
Widget build(BuildContext context) {
return BottomNavigationBar(
type: BottomNavigationBarType.fixed,
backgroundColor: Colors.red,
selectedItemColor: Colors.black,
unselectedItemColor: Colors.black54,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.shopping_cart),
label: 'Buy',
),
BottomNavigationBarItem(
icon: Icon(Icons.attach_money),
label: 'Sell',
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
label: 'Profile',
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
label: 'Settings',
),
],
currentIndex: _selectedIndex,
onTap: _onItemTapped,
);
MaterialColor get mdColor {
Map<int, Color> color = {
50: Color.fromRGBO(r, g, b, .1),
100: Color.fromRGBO(r, g, b, .2),
200: Color.fromRGBO(r, g, b, .3),
300: Color.fromRGBO(r, g, b, .4),
400: Color.fromRGBO(r, g, b, .5),
500: Color.fromRGBO(r, g, b, .6),
600: Color.fromRGBO(r, g, b, .7),
700: Color.fromRGBO(r, g, b, .8),
800: Color.fromRGBO(r, g, b, .9),
900: Color.fromRGBO(r, g, b, 1),
};
return MaterialColor(Color.fromRGBO(r, g, b, 1).value, color);
}
}

22
lib/main_screen.dart Normal file
View File

@@ -0,0 +1,22 @@
import 'package:flutter/material.dart';
class MainScreen extends StatefulWidget {
const MainScreen({ Key? key }) : super(key: key);
@override
_MainScreenState createState() => _MainScreenState();
}
class _MainScreenState extends State<MainScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Main Screen"),
),
body: const Center(
child: Text("Main Screen"),
),
);
}
}

View File

@@ -1,18 +0,0 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:ruswipeshare/home.dart';
import 'package:ruswipeshare/main.dart';
class SellScreen extends StatelessWidget {
const SellScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: const Text("Hi"),
),
bottomNavigationBar: MyNavBar(),
);
}
}

View File

@@ -201,30 +201,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.2.3+30"
firebase_ui_auth:
dependency: "direct main"
description:
name: firebase_ui_auth
sha256: "67b52b2f7d607355a07bae28d67f28e7b52a1e555a7f7cd1455f2e95be4d0816"
url: "https://pub.dev"
source: hosted
version: "1.1.14"
firebase_ui_localizations:
dependency: transitive
description:
name: firebase_ui_localizations
sha256: "8ab06ef14bbad6c2f8af63aa2995016996c205fd05db7912df18838a51d023e4"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
firebase_ui_oauth:
dependency: transitive
description:
name: firebase_ui_oauth
sha256: "77faba56761198f57b8939e4a93ef6dbabc1b972a22ff90ec1033dcff981a071"
url: "https://pub.dev"
source: hosted
version: "1.1.14"
flutter:
dependency: "direct main"
description: flutter
@@ -302,7 +278,7 @@ packages:
source: hosted
version: "0.4.3+20"
google_sign_in:
dependency: "direct main"
dependency: transitive
description:
name: google_sign_in
sha256: "821f354c053d51a2d417b02d42532a19a6ea8057d2f9ebb8863c07d81c98aaf9"
@@ -429,6 +405,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.1"
persistent_bottom_nav_bar:
dependency: "direct main"
description:
name: persistent_bottom_nav_bar
sha256: e2e031e3366fde01511e372a9a19d720a9b252bb456e5c8d77a30d7a4a2ddfb0
url: "https://pub.dev"
source: hosted
version: "5.0.2"
petitparser:
dependency: transitive
description:

View File

@@ -38,9 +38,8 @@ dependencies:
firebase_core: ^2.7.0
firebase_auth: ^4.2.9
flutterfire_ui: ^0.4.3+20
google_sign_in: ^5.4.4
flutter_dotenv: ^5.0.2
firebase_ui_auth: ^1.1.14
persistent_bottom_nav_bar: any
dev_dependencies:
flutter_test: