2026-04-04 14:43:29 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2026-04-04 19:25:55 +02:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2026-04-12 19:21:54 +02:00
|
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
2026-04-07 11:55:01 +02:00
|
|
|
import 'package:flux/core/blocs/session/session_bloc.dart';
|
2026-04-09 18:17:48 +02:00
|
|
|
import 'package:flux/core/routes/app_router.dart';
|
2026-04-07 11:30:22 +02:00
|
|
|
import 'package:flux/core/theme/theme.dart';
|
|
|
|
|
import 'package:flux/core/theme/bloc/theme_bloc.dart';
|
2026-04-07 11:55:01 +02:00
|
|
|
import 'package:flux/features/auth/bloc/auth_bloc.dart';
|
2026-04-09 11:30:57 +02:00
|
|
|
import 'package:flux/features/company/bloc/company_bloc.dart';
|
|
|
|
|
import 'package:flux/features/company/data/company_repository.dart';
|
2026-04-10 10:47:56 +02:00
|
|
|
import 'package:flux/features/customers/blocs/customer_bloc.dart';
|
|
|
|
|
import 'package:flux/features/customers/data/customer_repository.dart';
|
2026-04-12 19:21:54 +02:00
|
|
|
import 'package:flux/features/products/blocs/product_cubit.dart';
|
|
|
|
|
import 'package:flux/features/products/data/product_repository.dart';
|
2026-04-09 16:01:57 +02:00
|
|
|
import 'package:flux/features/store/bloc/store_bloc.dart';
|
2026-04-09 11:30:57 +02:00
|
|
|
import 'package:flux/features/store/data/store_repository.dart';
|
|
|
|
|
import 'package:flux/features/settings/settings.dart';
|
2026-04-04 19:25:55 +02:00
|
|
|
import 'package:get_it/get_it.dart';
|
2026-04-12 19:21:54 +02:00
|
|
|
import 'package:go_router/go_router.dart';
|
2026-04-04 19:25:55 +02:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2026-04-06 10:55:56 +02:00
|
|
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
2026-04-04 14:43:29 +02:00
|
|
|
|
2026-04-04 19:25:55 +02:00
|
|
|
void main() async {
|
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
2026-04-12 19:21:54 +02:00
|
|
|
await dotenv.load(fileName: ".env");
|
2026-04-09 11:30:57 +02:00
|
|
|
await setupLocator();
|
2026-04-06 10:55:56 +02:00
|
|
|
|
2026-04-05 10:06:26 +02:00
|
|
|
runApp(
|
2026-04-06 10:55:56 +02:00
|
|
|
MultiBlocProvider(
|
|
|
|
|
providers: [
|
2026-04-07 11:55:01 +02:00
|
|
|
BlocProvider<ThemeBloc>(
|
|
|
|
|
create: (context) => ThemeBloc()..add(LoadThemeEvent()),
|
|
|
|
|
),
|
2026-04-06 10:55:56 +02:00
|
|
|
BlocProvider<SessionBloc>(
|
|
|
|
|
create: (context) => SessionBloc()..add(AppStarted()),
|
|
|
|
|
),
|
|
|
|
|
],
|
2026-04-05 10:06:26 +02:00
|
|
|
child: const FluxApp(),
|
|
|
|
|
),
|
|
|
|
|
);
|
2026-04-04 14:43:29 +02:00
|
|
|
}
|
|
|
|
|
|
2026-04-09 11:30:57 +02:00
|
|
|
Future<void> setupLocator() async {
|
|
|
|
|
final GetIt getIt = GetIt.instance;
|
|
|
|
|
getIt.registerSingleton<SharedPreferences>(
|
|
|
|
|
await SharedPreferences.getInstance(),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await Supabase.initialize(
|
2026-04-12 19:21:54 +02:00
|
|
|
url: dotenv.env['SUPABASE_URL'] ?? '',
|
|
|
|
|
anonKey: dotenv.env['SUPABASE_ANON_KEY'] ?? '',
|
2026-04-09 11:30:57 +02:00
|
|
|
);
|
|
|
|
|
getIt.registerSingleton<SupabaseClient>(Supabase.instance.client);
|
|
|
|
|
getIt.registerLazySingleton<AppSettings>(() => AppSettings());
|
|
|
|
|
getIt.registerLazySingleton<CompanyRepository>(() => CompanyRepository());
|
|
|
|
|
getIt.registerLazySingleton<StoreRepository>(() => StoreRepository());
|
2026-04-10 10:47:56 +02:00
|
|
|
getIt.registerLazySingleton<CustomerRepository>(() => CustomerRepository());
|
2026-04-12 19:21:54 +02:00
|
|
|
getIt.registerLazySingleton<ProductRepository>(() => ProductRepository());
|
2026-04-09 11:30:57 +02:00
|
|
|
}
|
|
|
|
|
|
2026-04-12 19:21:54 +02:00
|
|
|
class FluxApp extends StatefulWidget {
|
2026-04-05 10:06:26 +02:00
|
|
|
const FluxApp({super.key});
|
2026-04-04 14:43:29 +02:00
|
|
|
|
|
|
|
|
@override
|
2026-04-12 19:21:54 +02:00
|
|
|
State<FluxApp> createState() => _FluxAppState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _FluxAppState extends State<FluxApp> {
|
|
|
|
|
late final GoRouter _router;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
// Lo creiamo una volta sola all'avvio dell'app
|
|
|
|
|
_router = AppRouter.createRouter(context.read<SessionBloc>());
|
|
|
|
|
}
|
2026-04-06 10:55:56 +02:00
|
|
|
|
2026-04-12 19:21:54 +02:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return MultiBlocProvider(
|
|
|
|
|
providers: [
|
|
|
|
|
BlocProvider<AuthBloc>(create: (_) => AuthBloc()),
|
|
|
|
|
BlocProvider<CompanyBloc>(create: (_) => CompanyBloc()),
|
|
|
|
|
BlocProvider<StoreBloc>(create: (_) => StoreBloc()),
|
|
|
|
|
BlocProvider<CustomerBloc>(create: (_) => CustomerBloc()),
|
|
|
|
|
BlocProvider<ProductCubit>(
|
|
|
|
|
create: (context) => ProductCubit(context.read<SessionBloc>()),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
child: BlocBuilder<ThemeBloc, ThemeState>(
|
|
|
|
|
builder: (context, state) {
|
|
|
|
|
return MaterialApp.router(
|
|
|
|
|
title: 'FLUX Gestionale',
|
|
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
|
theme: fluxLightTheme,
|
|
|
|
|
darkTheme: fluxDarkTheme,
|
|
|
|
|
themeMode: state.currentTheme.themeMode,
|
|
|
|
|
routerConfig: _router, // Usa l'istanza mantenuta nello stato
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
2026-04-06 10:55:56 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|