products data
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flux/core/blocs/session/session_bloc.dart';
|
||||
import 'package:flux/core/routes/app_router.dart';
|
||||
import 'package:flux/core/theme/theme.dart';
|
||||
@@ -9,15 +10,19 @@ import 'package:flux/features/company/bloc/company_bloc.dart';
|
||||
import 'package:flux/features/company/data/company_repository.dart';
|
||||
import 'package:flux/features/customers/blocs/customer_bloc.dart';
|
||||
import 'package:flux/features/customers/data/customer_repository.dart';
|
||||
import 'package:flux/features/products/blocs/product_cubit.dart';
|
||||
import 'package:flux/features/products/data/product_repository.dart';
|
||||
import 'package:flux/features/store/bloc/store_bloc.dart';
|
||||
import 'package:flux/features/store/data/store_repository.dart';
|
||||
import 'package:flux/features/settings/settings.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await dotenv.load(fileName: ".env");
|
||||
await setupLocator();
|
||||
|
||||
runApp(
|
||||
@@ -29,10 +34,6 @@ void main() async {
|
||||
BlocProvider<SessionBloc>(
|
||||
create: (context) => SessionBloc()..add(AppStarted()),
|
||||
),
|
||||
BlocProvider<AuthBloc>(create: (context) => AuthBloc()),
|
||||
BlocProvider<CompanyBloc>(create: (context) => CompanyBloc()),
|
||||
BlocProvider<StoreBloc>(create: (context) => StoreBloc()),
|
||||
BlocProvider<CustomerBloc>(create: (context) => CustomerBloc()),
|
||||
],
|
||||
child: const FluxApp(),
|
||||
),
|
||||
@@ -46,41 +47,58 @@ Future<void> setupLocator() async {
|
||||
);
|
||||
|
||||
await Supabase.initialize(
|
||||
url: 'https://pvqpjloswwvtfoxbkfbh.supabase.co',
|
||||
anonKey:
|
||||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InB2cXBqbG9zd3d2dGZveGJrZmJoIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzQ5MjkyNjgsImV4cCI6MjA5MDUwNTI2OH0.-7nitlX1pzPGscGawlIF0vhwuD_w209FUU0PxDNGm0Y',
|
||||
url: dotenv.env['SUPABASE_URL'] ?? '',
|
||||
anonKey: dotenv.env['SUPABASE_ANON_KEY'] ?? '',
|
||||
);
|
||||
getIt.registerSingleton<SupabaseClient>(Supabase.instance.client);
|
||||
getIt.registerLazySingleton<AppSettings>(() => AppSettings());
|
||||
getIt.registerLazySingleton<CompanyRepository>(() => CompanyRepository());
|
||||
getIt.registerLazySingleton<StoreRepository>(() => StoreRepository());
|
||||
getIt.registerLazySingleton<CustomerRepository>(() => CustomerRepository());
|
||||
getIt.registerLazySingleton<ProductRepository>(() => ProductRepository());
|
||||
}
|
||||
|
||||
class FluxApp extends StatelessWidget {
|
||||
class FluxApp extends StatefulWidget {
|
||||
const FluxApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<ThemeBloc, ThemeState>(
|
||||
builder: (context, state) {
|
||||
// Creiamo il router passando il SessionBloc che è già nell'albero grazie al MultiBlocProvider
|
||||
final router = AppRouter.createRouter(context.read<SessionBloc>());
|
||||
State<FluxApp> createState() => _FluxAppState();
|
||||
}
|
||||
|
||||
return BlocBuilder<ThemeBloc, ThemeState>(
|
||||
builder: (context, state) {
|
||||
return MaterialApp.router(
|
||||
// <--- Diventa .router
|
||||
title: 'FLUX Gestionale',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: fluxLightTheme,
|
||||
darkTheme: fluxDarkTheme,
|
||||
themeMode: state.currentTheme.themeMode,
|
||||
routerConfig: router, // <--- Configurazione GoRouter
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
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>());
|
||||
}
|
||||
|
||||
@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
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user