user cassé
This commit is contained in:
@ -1,16 +1,27 @@
|
||||
import 'package:em2rp/views/calendar_page.dart';
|
||||
import 'package:em2rp/views/login_page.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'firebase_options.dart';
|
||||
import 'utils/colors.dart';
|
||||
import 'views/my_account_page.dart';
|
||||
import 'views/user_management_page.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'providers/user_provider.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await Firebase.initializeApp(
|
||||
options: DefaultFirebaseOptions.currentPlatform,
|
||||
);
|
||||
runApp(const MyApp());
|
||||
runApp(
|
||||
ChangeNotifierProvider(
|
||||
// Wrap MyApp with ChangeNotifierProvider
|
||||
create: (context) => UserProvider(), // Create UserProvider instance
|
||||
child: const MyApp(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
@ -18,15 +29,9 @@ class MyApp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
print("test");
|
||||
return MaterialApp(
|
||||
title: 'EM2 ERP',
|
||||
initialRoute: '/',
|
||||
routes: {
|
||||
'/': (context) =>
|
||||
LoginPage(), // Remplacez HomePage par votre page d'accueil
|
||||
'/calendar': (context) =>
|
||||
CalendarPage(), // Ajoutez cette ligne pour la route /calendar
|
||||
},
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.red,
|
||||
primaryColor: AppColors.noir,
|
||||
@ -63,6 +68,31 @@ class MyApp extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
routes: {
|
||||
'/login': (context) => const LoginPage(),
|
||||
'/calendar': (context) => const CalendarPage(),
|
||||
'/my_account': (context) => const MyAccountPage(),
|
||||
'/user_management': (context) => const UserManagementPage(),
|
||||
},
|
||||
// Conditionally set home based on authentication state
|
||||
home: StreamBuilder<User?>(
|
||||
stream: FirebaseAuth.instance.authStateChanges(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.active) {
|
||||
User? user = snapshot.data;
|
||||
if (user == null) {
|
||||
return const LoginPage(); // User not logged in, show LoginPage
|
||||
}
|
||||
return const CalendarPage(); // User logged in, show CalendarPage
|
||||
}
|
||||
// Checking auth state, show loading indicator
|
||||
return const Scaffold(
|
||||
body: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user