From 81f6cf5b1f440ceb2b085cbd82c2e456454eadf0 Mon Sep 17 00:00:00 2001 From: Josh Patra Date: Sat, 25 Feb 2023 19:29:10 -0500 Subject: [PATCH] --- lib/home.dart | 152 +++++++++++++++++++++++++------------------ lib/main.dart | 102 +++++++++-------------------- lib/main_screen.dart | 22 +++++++ lib/sell.dart | 18 ----- pubspec.lock | 34 +++------- pubspec.yaml | 3 +- 6 files changed, 151 insertions(+), 180 deletions(-) create mode 100644 lib/main_screen.dart delete mode 100644 lib/sell.dart diff --git a/lib/home.dart b/lib/home.dart index 132742a..b712f5c 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -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 { -// int _selectedIndex = 0; +class _HomeScreenState extends State { + late PersistentTabController _controller; + @override + void initState() { + super.initState(); + _controller = PersistentTabController(); + } + List _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 _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. + ); + } +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 0bac118..9b07f7b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,87 +1,49 @@ 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'; void main() async { - WidgetsFlutterBinding.ensureInitialized(); + WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); runApp(const MyApp()); } class MyApp extends StatelessWidget { - const MyApp({super.key}); - @override - Widget build(BuildContext context) { - return MaterialApp( - theme: ThemeData( - primarySwatch: Colors.blue, - ), - home: const HomeScreen(), - ); - } + + const MyApp({super.key}); + @override + Widget build(BuildContext context) { + return MaterialApp( + theme: ThemeData( + primarySwatch: CustomMaterialColor(200,61,61).mdColor, + ), + 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 createState() => MyNavBarState(); -} - -class MyNavBarState extends State { - 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)), - ); + MaterialColor get mdColor { + Map 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); } - - @override - Widget build(BuildContext context) { - return BottomNavigationBar( - type: BottomNavigationBarType.fixed, - backgroundColor: Colors.red, - selectedItemColor: Colors.black, - unselectedItemColor: Colors.black54, - items: const [ - 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, - ); - } -} +} \ No newline at end of file diff --git a/lib/main_screen.dart b/lib/main_screen.dart new file mode 100644 index 0000000..e2af9bb --- /dev/null +++ b/lib/main_screen.dart @@ -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 { + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text("Main Screen"), + ), + body: const Center( + child: Text("Main Screen"), + ), + ); + } +} \ No newline at end of file diff --git a/lib/sell.dart b/lib/sell.dart deleted file mode 100644 index 0a56024..0000000 --- a/lib/sell.dart +++ /dev/null @@ -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(), - ); - } -} diff --git a/pubspec.lock b/pubspec.lock index cb3f865..4c9d6c4 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: diff --git a/pubspec.yaml b/pubspec.yaml index b135cfe..93d6e46 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: