mirror of
https://github.com/SoPat712/RUSwipeShare.git
synced 2025-08-22 03:18:44 -04:00
Persisent navbar
This commit is contained in:
@@ -1,31 +1,10 @@
|
|||||||
import 'package:firebase_auth/firebase_auth.dart';
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
|
import 'package:ruswipeshare/main.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class HomeScreen extends StatelessWidget {
|
class HomeScreen extends StatelessWidget {
|
||||||
const HomeScreen({super.key});
|
const HomeScreen({super.key});
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return const StatefulHome();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class StatefulHome extends StatefulWidget {
|
|
||||||
const StatefulHome({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<StatefulHome> createState() => _StatefulHomeState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _StatefulHomeState extends State<StatefulHome> {
|
|
||||||
int _selectedIndex = 0;
|
|
||||||
|
|
||||||
void _onItemTapped(int index) {
|
|
||||||
setState(() {
|
|
||||||
_selectedIndex = index;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -46,32 +25,48 @@ class _StatefulHomeState extends State<StatefulHome> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
bottomNavigationBar: BottomNavigationBar(
|
bottomNavigationBar: MyNavBar(),
|
||||||
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,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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(),
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
@@ -1,27 +1,87 @@
|
|||||||
import 'package:firebase_core/firebase_core.dart';
|
import 'package:firebase_core/firebase_core.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:ruswipeshare/home.dart';
|
import 'package:ruswipeshare/home.dart';
|
||||||
|
import 'package:ruswipeshare/sell.dart';
|
||||||
|
|
||||||
import 'firebase_options.dart';
|
import 'firebase_options.dart';
|
||||||
import 'authGate.dart';
|
import 'authGate.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
// WidgetsFlutterBinding.ensureInitialized();
|
||||||
await Firebase.initializeApp(
|
// await Firebase.initializeApp(
|
||||||
options: DefaultFirebaseOptions.android,
|
// options: DefaultFirebaseOptions.android,
|
||||||
);
|
// );
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
const MyApp({super.key});
|
const MyApp({super.key});
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
primarySwatch: Colors.blue,
|
primarySwatch: Colors.blue,
|
||||||
),
|
),
|
||||||
home: const AuthGate(),
|
home: const HomeScreen(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyNavBar extends StatefulWidget {
|
||||||
|
MyNavBar({super.key});
|
||||||
|
|
||||||
|
@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,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
18
lib/sell.dart
Normal file
18
lib/sell.dart
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
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(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user