|
@@ -6,7 +6,8 @@ import 'package:ristoris/providers/database_provider.dart';
|
|
|
import '../../../providers/auth_provider.dart';
|
|
import '../../../providers/auth_provider.dart';
|
|
|
import '../../../providers/dashboard_provider.dart';
|
|
import '../../../providers/dashboard_provider.dart';
|
|
|
import '../../../core/responsive.dart';
|
|
import '../../../core/responsive.dart';
|
|
|
-import '../../widgets/app_drawer.dart';
|
|
|
|
|
|
|
+import '../../../services/database_export_service.dart';
|
|
|
|
|
+import '../../widgets/persistent_sidebar.dart';
|
|
|
|
|
|
|
|
class DashboardPage extends ConsumerWidget {
|
|
class DashboardPage extends ConsumerWidget {
|
|
|
const DashboardPage({super.key});
|
|
const DashboardPage({super.key});
|
|
@@ -20,38 +21,52 @@ class DashboardPage extends ConsumerWidget {
|
|
|
final agentiAsync = ref.watch(agentiListProvider);
|
|
final agentiAsync = ref.watch(agentiListProvider);
|
|
|
final theme = Theme.of(context);
|
|
final theme = Theme.of(context);
|
|
|
|
|
|
|
|
|
|
+ final dashboardBody = SafeArea(
|
|
|
|
|
+ child: dashboardAsync?.when(
|
|
|
|
|
+ data: (data) {
|
|
|
|
|
+ final agentiList = agentiAsync.asData?.value;
|
|
|
|
|
+ final hasMultipleAgents =
|
|
|
|
|
+ agentiList != null && agentiList.length > 1;
|
|
|
|
|
+ return _DashboardContent(
|
|
|
|
|
+ data: data,
|
|
|
|
|
+ theme: theme,
|
|
|
|
|
+ hasMultipleAgents: hasMultipleAgents,
|
|
|
|
|
+ );
|
|
|
|
|
+ },
|
|
|
|
|
+ loading: () => const Center(child: CircularProgressIndicator()),
|
|
|
|
|
+ error: (e, _) => Center(child: Text('Errore: $e')),
|
|
|
|
|
+ ) ??
|
|
|
|
|
+ const Center(child: CircularProgressIndicator()),
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ if (ResponsiveBreakpoints.showPersistentSidebar(context)) {
|
|
|
|
|
+ return Row(
|
|
|
|
|
+ children: [
|
|
|
|
|
+ PersistentSidebar(
|
|
|
|
|
+ onExportDatabase: () => DatabaseExportService.export(context),
|
|
|
|
|
+ ),
|
|
|
|
|
+ Expanded(
|
|
|
|
|
+ child: Scaffold(
|
|
|
|
|
+ appBar: AppBar(
|
|
|
|
|
+ title: Text(
|
|
|
|
|
+ 'Benvenuto, ${agente?.ragioneSociale ?? ''}',
|
|
|
|
|
+ ),
|
|
|
|
|
+ ),
|
|
|
|
|
+ body: dashboardBody,
|
|
|
|
|
+ ),
|
|
|
|
|
+ ),
|
|
|
|
|
+ ],
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return Scaffold(
|
|
return Scaffold(
|
|
|
appBar: AppBar(title: Text('Benvenuto, ${agente?.ragioneSociale ?? ''}')),
|
|
appBar: AppBar(title: Text('Benvenuto, ${agente?.ragioneSociale ?? ''}')),
|
|
|
- drawer: AppDrawer(
|
|
|
|
|
- agente: agente,
|
|
|
|
|
- onDashboard: () => context.go('/dashboard'),
|
|
|
|
|
- onOrders: () => context.go('/dashboard/orders'),
|
|
|
|
|
- onCustomers: () => context.go('/dashboard/customers'),
|
|
|
|
|
- onCatalog: () => context.go('/dashboard/catalog'),
|
|
|
|
|
- onPromotions: () => context.go('/dashboard/promotions'),
|
|
|
|
|
- onPayments: () => context.go('/dashboard/payments'),
|
|
|
|
|
- onStatistics: () => context.go('/dashboard/statistics'),
|
|
|
|
|
- onSync: () => context.go('/dashboard/sync'),
|
|
|
|
|
- onSwitchAgent: () => context.go('/dashboard/switch-agent'),
|
|
|
|
|
- onLogout: () => ref.read(authProvider.notifier).logout(),
|
|
|
|
|
- ),
|
|
|
|
|
- body: SafeArea(
|
|
|
|
|
- child: dashboardAsync?.when(
|
|
|
|
|
- data: (data) {
|
|
|
|
|
- final agentiList = agentiAsync.asData?.value;
|
|
|
|
|
- final hasMultipleAgents =
|
|
|
|
|
- agentiList != null && agentiList.length > 1;
|
|
|
|
|
- return _DashboardContent(
|
|
|
|
|
- data: data,
|
|
|
|
|
- theme: theme,
|
|
|
|
|
- hasMultipleAgents: hasMultipleAgents,
|
|
|
|
|
- );
|
|
|
|
|
- },
|
|
|
|
|
- loading: () => const Center(child: CircularProgressIndicator()),
|
|
|
|
|
- error: (e, _) => Center(child: Text('Errore: $e')),
|
|
|
|
|
- ) ??
|
|
|
|
|
- const Center(child: CircularProgressIndicator()),
|
|
|
|
|
|
|
+ drawer: Drawer(
|
|
|
|
|
+ child: PersistentSidebar(
|
|
|
|
|
+ onExportDatabase: () => DatabaseExportService.export(context),
|
|
|
|
|
+ ),
|
|
|
),
|
|
),
|
|
|
|
|
+ body: dashboardBody,
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|