auth
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/blocs/session/session_bloc.dart';
|
||||
import 'package:flux/theme/theme.dart';
|
||||
import 'package:flux/theme/theme_bloc.dart';
|
||||
import 'package:flux/ui/auth/auth_screen.dart';
|
||||
import 'package:flux/ui/home_screen.dart';
|
||||
import 'package:flux/ui/settings/settings.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@@ -14,9 +17,21 @@ void main() async {
|
||||
await SharedPreferences.getInstance(),
|
||||
);
|
||||
getIt.registerSingleton<AppSettings>(AppSettings());
|
||||
await Supabase.initialize(
|
||||
url: 'https://pvqpjloswwvtfoxbkfbh.supabase.co',
|
||||
anonKey:
|
||||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InB2cXBqbG9zd3d2dGZveGJrZmJoIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzQ5MjkyNjgsImV4cCI6MjA5MDUwNTI2OH0.-7nitlX1pzPGscGawlIF0vhwuD_w209FUU0PxDNGm0Y',
|
||||
);
|
||||
getIt.registerSingleton<SupabaseClient>(Supabase.instance.client);
|
||||
|
||||
runApp(
|
||||
BlocProvider(
|
||||
create: (context) => ThemeBloc()..add(LoadThemeEvent()),
|
||||
MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(create: (context) => ThemeBloc()..add(LoadThemeEvent())),
|
||||
BlocProvider<SessionBloc>(
|
||||
create: (context) => SessionBloc()..add(AppStarted()),
|
||||
),
|
||||
],
|
||||
child: const FluxApp(),
|
||||
),
|
||||
);
|
||||
@@ -35,9 +50,41 @@ class FluxApp extends StatelessWidget {
|
||||
theme: fluxLightTheme,
|
||||
darkTheme: fluxDarkTheme,
|
||||
themeMode: state.currentTheme.themeMode, // Applica il tema FLUX
|
||||
home: const HomeScreen(),
|
||||
home: const AuthGuard(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AuthGuard extends StatelessWidget {
|
||||
const AuthGuard({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<SessionBloc, SessionState>(
|
||||
builder: (context, state) {
|
||||
switch (state.status) {
|
||||
case SessionStatus.unauthenticated:
|
||||
return const AuthScreen();
|
||||
|
||||
case SessionStatus.authenticatedNoCompany:
|
||||
// Pagina forzata per inserimento P.IVA e Ragione Sociale
|
||||
return const CreateCompanyScreen();
|
||||
|
||||
case SessionStatus.authenticatedNoStore:
|
||||
// Pagina forzata per creare il primo punto vendita
|
||||
return const CreateStoreScreen();
|
||||
|
||||
case SessionStatus.ready:
|
||||
return const HomeScreen(); // Entra direttamente nel negozio salvato
|
||||
|
||||
default:
|
||||
return const Scaffold(
|
||||
body: Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user