97 lines
3.2 KiB
Dart
97 lines
3.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flux/core/blocs/session/session_bloc.dart';
|
|
import 'package:flux/core/theme/theme.dart';
|
|
import 'package:flux/core/theme/bloc/theme_bloc.dart';
|
|
import 'package:flux/features/auth/bloc/auth_bloc.dart';
|
|
import 'package:flux/features/auth/ui/auth_screen.dart';
|
|
import 'package:flux/features/company/ui/create_company_screen.dart';
|
|
import 'package:flux/features/store/ui/create_store_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();
|
|
final GetIt getIt = GetIt.instance;
|
|
getIt.registerSingleton<SharedPreferences>(
|
|
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(
|
|
MultiBlocProvider(
|
|
providers: [
|
|
BlocProvider<ThemeBloc>(
|
|
create: (context) => ThemeBloc()..add(LoadThemeEvent()),
|
|
),
|
|
BlocProvider<SessionBloc>(
|
|
create: (context) => SessionBloc()..add(AppStarted()),
|
|
),
|
|
BlocProvider<AuthBloc>(create: (context) => AuthBloc()),
|
|
],
|
|
child: const FluxApp(),
|
|
),
|
|
);
|
|
}
|
|
|
|
class FluxApp extends StatelessWidget {
|
|
const FluxApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocBuilder<ThemeBloc, ThemeState>(
|
|
builder: (context, state) {
|
|
return MaterialApp(
|
|
title: 'FLUX Gestionale',
|
|
debugShowCheckedModeBanner: false,
|
|
theme: fluxLightTheme,
|
|
darkTheme: fluxDarkTheme,
|
|
themeMode: state.currentTheme.themeMode, // Applica il tema FLUX
|
|
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()),
|
|
);
|
|
}
|
|
},
|
|
);
|
|
}
|
|
}
|