named router with constants to prevent silent bugs
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
import 'package:flux/core/data/core_repository.dart';
|
||||
import 'package:flux/core/layout/app_shell.dart';
|
||||
import 'package:flux/core/routes/routes.dart';
|
||||
import 'package:flux/core/widgets/image_upload/blocs/image_upload_cubit.dart';
|
||||
import 'package:flux/core/widgets/image_upload/ui/image_upload_screen.dart';
|
||||
import 'package:flux/core/widgets/set_password_screen.dart';
|
||||
@@ -42,27 +43,6 @@ import 'package:flux/features/tickets/ui/ticket_list_screen.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
const String loginRoute = 'login';
|
||||
const String setPasswordRoute = 'set-password';
|
||||
const String onboardingRoute = 'onboarding';
|
||||
const String homeRoute = 'home';
|
||||
const String masterDataRoute = 'master-data';
|
||||
const String productsRoute = 'products';
|
||||
const String companySettingsRoute = 'company-settings';
|
||||
const String staffRoute = 'staff';
|
||||
const String storesRoute = 'stores';
|
||||
const String providersRoute = 'providers';
|
||||
const String settingsRoute = 'settings';
|
||||
const String themeRoute = 'theme';
|
||||
const String operationsRoute = 'operations';
|
||||
const String customersRoute = 'customers';
|
||||
const String ticketsRoute = 'tickets';
|
||||
const String ticketFormRoute = 'ticket-form';
|
||||
const String operationFormRoute = 'operation-form';
|
||||
const String uploadSuccessRoute = 'upload-success';
|
||||
const String customerFormRoute = 'customer-form';
|
||||
const String uploadRoute = 'upload';
|
||||
|
||||
class AppRouter {
|
||||
static GoRouter createRouter(SessionCubit sessionCubit) {
|
||||
return GoRouter(
|
||||
@@ -113,17 +93,17 @@ class AppRouter {
|
||||
// --- ROTTE DI SERVIZIO (FUORI DALLA SHELL) ---
|
||||
GoRoute(
|
||||
path: '/login',
|
||||
name: 'login',
|
||||
name: Routes.login,
|
||||
builder: (context, state) => const AuthScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/set-password',
|
||||
name: 'set-password',
|
||||
name: Routes.setPassword,
|
||||
builder: (context, state) => const SetPasswordScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/onboarding',
|
||||
name: 'onboarding',
|
||||
name: Routes.onboarding,
|
||||
builder: (context, state) => BlocProvider(
|
||||
create: (context) => OnboardingCubit(
|
||||
GetIt.I.get<SessionCubit>(),
|
||||
@@ -140,19 +120,19 @@ class AppRouter {
|
||||
// 1. DASHBOARD
|
||||
GoRoute(
|
||||
path: '/',
|
||||
name: homeRoute,
|
||||
name: Routes.home,
|
||||
builder: (context, state) => const HomeScreen(),
|
||||
),
|
||||
|
||||
// 2. HUB ANAGRAFICHE E SOTTO-ROTTE
|
||||
GoRoute(
|
||||
path: '/master-data',
|
||||
name: masterDataRoute,
|
||||
name: Routes.masterData,
|
||||
builder: (context, state) => const MasterDataHubScreen(),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: 'products', // Diventa /master-data/products
|
||||
name: 'products',
|
||||
name: Routes.products,
|
||||
builder: (context, state) {
|
||||
context.read<ProductsCubit>().refreshCubit();
|
||||
|
||||
@@ -161,7 +141,7 @@ class AppRouter {
|
||||
),
|
||||
GoRoute(
|
||||
path: 'company-settings',
|
||||
name: companySettingsRoute,
|
||||
name: Routes.companySettings,
|
||||
builder: (context, state) => BlocProvider(
|
||||
create: (context) => CompanySettingsCubit(),
|
||||
child: const CompanySettingsScreen(),
|
||||
@@ -169,17 +149,17 @@ class AppRouter {
|
||||
),
|
||||
GoRoute(
|
||||
path: 'staff',
|
||||
name: staffRoute, // Diventa /master-data/staff
|
||||
name: Routes.staff, // Diventa /master-data/staff
|
||||
builder: (context, state) => const StaffScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: storesRoute,
|
||||
path: Routes.stores,
|
||||
name: 'stores', // Diventa /master-data/stores
|
||||
builder: (context, state) => const StoresScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: 'providers',
|
||||
name: providersRoute, // Diventa /master-data/providers
|
||||
name: Routes.providers, // Diventa /master-data/providers
|
||||
builder: (context, state) =>
|
||||
const ProvidersMasterDataScreen(),
|
||||
),
|
||||
@@ -189,19 +169,19 @@ class AppRouter {
|
||||
// 3. IMPOSTAZIONI
|
||||
GoRoute(
|
||||
path: '/settings',
|
||||
name: settingsRoute,
|
||||
name: Routes.settings,
|
||||
builder: (context, state) => const SettingsView(),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: 'theme',
|
||||
name: themeRoute,
|
||||
path: 'themeSettings',
|
||||
name: Routes.themeSettings,
|
||||
builder: (context, state) => const ThemeSettingsView(),
|
||||
),
|
||||
],
|
||||
),
|
||||
GoRoute(
|
||||
path: '/operations',
|
||||
name: operationsRoute,
|
||||
name: Routes.operations,
|
||||
builder: (context, state) => BlocProvider(
|
||||
create: (context) => OperationListCubit(),
|
||||
child: const OperationListScreen(),
|
||||
@@ -209,13 +189,13 @@ class AppRouter {
|
||||
),
|
||||
GoRoute(
|
||||
path: '/customers',
|
||||
name: customersRoute,
|
||||
name: Routes.customers,
|
||||
builder: (context, state) =>
|
||||
const CustomersContent(), // O come si chiama il tuo widget della lista!
|
||||
),
|
||||
GoRoute(
|
||||
path: '/tickets',
|
||||
name: ticketsRoute,
|
||||
name: Routes.tickets,
|
||||
builder: (context, state) => BlocProvider(
|
||||
create: (context) => TicketListCubit(),
|
||||
child: const TicketListScreen(),
|
||||
@@ -228,7 +208,7 @@ class AppRouter {
|
||||
GoRoute(
|
||||
// Il path sarà es. /tickets/form/123 oppure /tickets/form/new
|
||||
path: '/tickets/form/:id',
|
||||
name: ticketFormRoute,
|
||||
name: Routes.ticketForm,
|
||||
builder: (context, state) {
|
||||
// 1. Leggiamo l'ID dall'URL
|
||||
final String pathId = state.pathParameters['id'] ?? 'new';
|
||||
@@ -265,7 +245,7 @@ class AppRouter {
|
||||
),
|
||||
GoRoute(
|
||||
path: '/upload-success',
|
||||
name: uploadSuccessRoute,
|
||||
name: Routes.uploadSuccess,
|
||||
builder: (context, state) => const UploadSuccessScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
@@ -285,7 +265,7 @@ class AppRouter {
|
||||
|
||||
GoRoute(
|
||||
path: '/operations/form/:id',
|
||||
name: operationFormRoute,
|
||||
name: Routes.operationForm,
|
||||
builder: (context, state) {
|
||||
final String pathId = state.pathParameters['id'] ?? 'new';
|
||||
final OperationModel? operationFromExtra =
|
||||
@@ -324,7 +304,7 @@ class AppRouter {
|
||||
|
||||
GoRoute(
|
||||
path: '/upload/:type/:id',
|
||||
name: uploadRoute,
|
||||
name: Routes.upload,
|
||||
builder: (context, state) {
|
||||
final typeString = state.pathParameters['type']!;
|
||||
final id = state.pathParameters['id']!;
|
||||
|
||||
Reference in New Issue
Block a user