2026-04-09 19:25:32 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2026-04-22 11:06:02 +02:00
|
|
|
import 'package:flux/core/blocs/session/session_cubit.dart';
|
2026-04-09 19:25:32 +02:00
|
|
|
import 'package:flux/core/theme/theme.dart';
|
2026-04-29 19:25:48 +02:00
|
|
|
import 'package:flux/core/utils/extensions.dart';
|
2026-04-29 11:40:17 +02:00
|
|
|
import 'package:flux/features/home/ui/quick_actions_widget.dart';
|
|
|
|
|
import 'package:flux/features/master_data/staff/blocs/staff_cubit.dart';
|
|
|
|
|
import 'package:go_router/go_router.dart';
|
2026-04-09 19:25:32 +02:00
|
|
|
|
2026-04-29 11:40:17 +02:00
|
|
|
class HomeScreen extends StatelessWidget {
|
2026-04-09 19:25:32 +02:00
|
|
|
const HomeScreen({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
2026-04-29 11:40:17 +02:00
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final theme = Theme.of(context);
|
2026-04-09 19:25:32 +02:00
|
|
|
|
2026-04-29 11:40:17 +02:00
|
|
|
return Scaffold(
|
|
|
|
|
backgroundColor: theme.colorScheme.surface,
|
|
|
|
|
body: SafeArea(
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
// ==========================================
|
|
|
|
|
// 1. HEADER FISSO (Non scrolla mai)
|
|
|
|
|
// ==========================================
|
|
|
|
|
Container(
|
|
|
|
|
padding: const EdgeInsets.all(24.0),
|
|
|
|
|
// Un leggero colore di sfondo aiuta a staccare l'header quando il contenuto ci passa sotto
|
|
|
|
|
color: theme.colorScheme.surface,
|
|
|
|
|
child: _buildHeader(context, theme),
|
|
|
|
|
),
|
2026-04-09 19:25:32 +02:00
|
|
|
|
2026-04-29 11:40:17 +02:00
|
|
|
// ==========================================
|
|
|
|
|
// 2. CORPO DELLA DASHBOARD (Scrollabile)
|
|
|
|
|
// ==========================================
|
|
|
|
|
Expanded(
|
|
|
|
|
child: CustomScrollView(
|
|
|
|
|
slivers: [
|
|
|
|
|
// --- QUICK ACTIONS: AZIONI RAPIDE ---
|
|
|
|
|
SliverToBoxAdapter(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
|
|
|
|
child: _buildQuickActions(context),
|
|
|
|
|
),
|
|
|
|
|
),
|
2026-04-16 11:50:29 +02:00
|
|
|
|
2026-04-29 11:40:17 +02:00
|
|
|
const SliverToBoxAdapter(child: SizedBox(height: 32)),
|
2026-04-09 19:25:32 +02:00
|
|
|
|
2026-04-29 11:40:17 +02:00
|
|
|
// --- I WIDGET DELLA DASHBOARD (Responsive Grid) ---
|
|
|
|
|
SliverPadding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
|
|
|
|
sliver: SliverGrid(
|
|
|
|
|
gridDelegate:
|
|
|
|
|
const SliverGridDelegateWithMaxCrossAxisExtent(
|
|
|
|
|
maxCrossAxisExtent: 500,
|
|
|
|
|
mainAxisSpacing: 16,
|
|
|
|
|
crossAxisSpacing: 16,
|
|
|
|
|
childAspectRatio: 1.3,
|
|
|
|
|
),
|
|
|
|
|
delegate: SliverChildListDelegate([
|
|
|
|
|
_buildDashboardWidget(
|
2026-04-30 10:25:52 +02:00
|
|
|
title: context.l10n.homeExpiringContracts,
|
2026-04-29 11:40:17 +02:00
|
|
|
icon: Icons.assignment_late_outlined,
|
|
|
|
|
color: Colors.orange,
|
|
|
|
|
context: context,
|
|
|
|
|
),
|
|
|
|
|
_buildDashboardWidget(
|
2026-04-30 10:25:52 +02:00
|
|
|
title: context.l10n.commonStickyNotes,
|
2026-04-29 11:40:17 +02:00
|
|
|
icon: Icons.sticky_note_2_outlined,
|
|
|
|
|
color: Colors.yellow.shade700,
|
|
|
|
|
context: context,
|
|
|
|
|
),
|
|
|
|
|
_buildDashboardWidget(
|
2026-04-30 10:25:52 +02:00
|
|
|
title: context.l10n.homeMyTasks,
|
2026-04-29 11:40:17 +02:00
|
|
|
icon: Icons.check_box_outlined,
|
|
|
|
|
color: Colors.green,
|
|
|
|
|
context: context,
|
2026-04-20 16:52:20 +02:00
|
|
|
),
|
2026-04-29 11:40:17 +02:00
|
|
|
_buildDashboardWidget(
|
2026-04-30 10:25:52 +02:00
|
|
|
title: context.l10n.homeLatestServices,
|
2026-04-29 11:40:17 +02:00
|
|
|
icon: Icons.design_services_outlined,
|
|
|
|
|
color: Colors.blue,
|
|
|
|
|
context: context,
|
|
|
|
|
),
|
|
|
|
|
_buildDashboardWidget(
|
2026-04-30 10:25:52 +02:00
|
|
|
title: context.l10n.homeLatestServiceTickets,
|
2026-04-29 11:40:17 +02:00
|
|
|
icon: Icons.support_agent_outlined,
|
|
|
|
|
color: Colors.purple,
|
|
|
|
|
context: context,
|
|
|
|
|
),
|
|
|
|
|
]),
|
2026-04-20 16:52:20 +02:00
|
|
|
),
|
2026-04-09 19:25:32 +02:00
|
|
|
),
|
2026-04-29 11:40:17 +02:00
|
|
|
|
|
|
|
|
// Spazio finale per non far attaccare l'ultima card al fondo
|
|
|
|
|
const SliverToBoxAdapter(child: SizedBox(height: 40)),
|
2026-04-09 19:25:32 +02:00
|
|
|
],
|
|
|
|
|
),
|
2026-04-20 16:52:20 +02:00
|
|
|
),
|
|
|
|
|
],
|
2026-04-13 10:00:07 +02:00
|
|
|
),
|
2026-04-20 16:52:20 +02:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-29 11:40:17 +02:00
|
|
|
// ==========================================
|
|
|
|
|
// WIDGET BUILDERS
|
|
|
|
|
// ==========================================
|
2026-04-13 10:00:07 +02:00
|
|
|
|
2026-04-29 11:40:17 +02:00
|
|
|
Widget _buildHeader(BuildContext context, ThemeData theme) {
|
|
|
|
|
final user = context.watch<SessionCubit>().state.currentStaffMember;
|
|
|
|
|
final currentStore = context.watch<SessionCubit>().state.currentStore;
|
|
|
|
|
|
|
|
|
|
return Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
2026-04-30 10:25:52 +02:00
|
|
|
context.l10n.homeWelcomeBack(user?.name ?? "Utente"),
|
2026-04-29 11:40:17 +02:00
|
|
|
style: theme.textTheme.headlineMedium?.copyWith(
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
letterSpacing: -0.5,
|
|
|
|
|
color: context.primaryText, // Uso dell'estensione!
|
|
|
|
|
),
|
2026-04-20 16:52:20 +02:00
|
|
|
),
|
2026-04-29 11:40:17 +02:00
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
|
|
|
|
|
InkWell(
|
|
|
|
|
onTap: () => _showStoreSelector(context, theme),
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
child: Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
|
horizontal: 12,
|
|
|
|
|
vertical: 6,
|
2026-04-20 16:52:20 +02:00
|
|
|
),
|
2026-04-29 11:40:17 +02:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: context.primary.withValues(
|
|
|
|
|
alpha: 0.08,
|
|
|
|
|
), // Sfondo delicato
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
border: Border.all(
|
|
|
|
|
color: context.primary.withValues(
|
|
|
|
|
alpha: 0.2,
|
|
|
|
|
), // Bordino netto
|
2026-04-20 16:52:20 +02:00
|
|
|
),
|
|
|
|
|
),
|
2026-04-29 11:40:17 +02:00
|
|
|
child: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
Icon(Icons.storefront, size: 16, color: context.primary),
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
Text(
|
2026-04-30 10:25:52 +02:00
|
|
|
currentStore?.nome ?? context.l10n.homeNoStoreFound,
|
2026-04-29 11:40:17 +02:00
|
|
|
style: TextStyle(
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
color: context.primary,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 4),
|
|
|
|
|
Icon(Icons.arrow_drop_down, color: context.primary),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
2026-04-20 16:52:20 +02:00
|
|
|
),
|
2026-04-29 11:40:17 +02:00
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
CircleAvatar(
|
|
|
|
|
radius: 24,
|
|
|
|
|
// Usiamo il Turchese (accent) in trasparenza per l'avatar
|
|
|
|
|
backgroundColor: context.accent.withValues(alpha: 0.15),
|
|
|
|
|
child: Icon(Icons.person, color: context.accent, size: 26),
|
|
|
|
|
),
|
|
|
|
|
],
|
2026-04-20 16:52:20 +02:00
|
|
|
);
|
|
|
|
|
}
|
2026-04-12 21:32:20 +02:00
|
|
|
|
2026-04-29 11:40:17 +02:00
|
|
|
Widget _buildQuickActions(BuildContext context) {
|
|
|
|
|
return SingleChildScrollView(
|
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
QuickActionButton(
|
|
|
|
|
icon: Icons.add,
|
2026-04-30 10:25:52 +02:00
|
|
|
label: context.l10n.commonService,
|
2026-04-29 11:40:17 +02:00
|
|
|
color: Colors.blue,
|
|
|
|
|
onTap: () {
|
|
|
|
|
// Entriamo nel form! Nessun parametro extra = Nuovo Servizio
|
|
|
|
|
context.push('/service-form');
|
|
|
|
|
},
|
2026-04-12 21:32:20 +02:00
|
|
|
),
|
2026-04-29 11:40:17 +02:00
|
|
|
const SizedBox(width: 12),
|
|
|
|
|
QuickActionButton(
|
|
|
|
|
icon: Icons.handyman,
|
2026-04-30 10:25:52 +02:00
|
|
|
label: context.l10n.homeNewServiceTicket,
|
2026-04-29 11:40:17 +02:00
|
|
|
color: Colors.redAccent,
|
|
|
|
|
onTap: () {
|
|
|
|
|
// TODO: Quando avrai la rotta per la nuova assistenza
|
|
|
|
|
// context.push('/assistance-form');
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
|
QuickActionButton(
|
|
|
|
|
icon: Icons.note_add,
|
2026-04-30 10:25:52 +02:00
|
|
|
label: context.l10n.commonNote,
|
2026-04-29 11:40:17 +02:00
|
|
|
color: Colors.amber,
|
|
|
|
|
onTap: () {
|
|
|
|
|
// TODO: Quando faremo il modale/pagina delle note
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
|
QuickActionButton(
|
|
|
|
|
icon: Icons.task_alt,
|
2026-04-30 10:25:52 +02:00
|
|
|
label: context.l10n.commonTask,
|
2026-04-29 11:40:17 +02:00
|
|
|
color: Colors.teal,
|
|
|
|
|
onTap: () {
|
|
|
|
|
// TODO: Quando faremo i task
|
2026-04-20 16:52:20 +02:00
|
|
|
},
|
2026-04-12 21:32:20 +02:00
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-29 11:40:17 +02:00
|
|
|
Widget _buildDashboardWidget({
|
|
|
|
|
required BuildContext context,
|
|
|
|
|
required String title,
|
|
|
|
|
required IconData icon,
|
|
|
|
|
required Color color,
|
|
|
|
|
}) {
|
|
|
|
|
final theme = Theme.of(context);
|
2026-04-20 16:52:20 +02:00
|
|
|
|
2026-04-29 11:40:17 +02:00
|
|
|
return Card(
|
|
|
|
|
elevation: 0,
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(16),
|
|
|
|
|
side: BorderSide(color: theme.dividerColor.withValues(alpha: 0.5)),
|
|
|
|
|
),
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Container(
|
|
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: color.withValues(alpha: 0.1),
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
),
|
|
|
|
|
child: Icon(icon, color: color, size: 20),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Text(
|
|
|
|
|
title,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
color: context.primaryText,
|
|
|
|
|
),
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: Icon(
|
|
|
|
|
Icons.more_vert,
|
|
|
|
|
size: 20,
|
|
|
|
|
color: context.secondaryText,
|
|
|
|
|
),
|
|
|
|
|
onPressed: () {},
|
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
|
constraints: const BoxConstraints(),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const Spacer(),
|
|
|
|
|
Center(
|
|
|
|
|
child: Text(
|
2026-04-30 10:25:52 +02:00
|
|
|
context.l10n.commonComingSoon,
|
2026-04-13 10:00:07 +02:00
|
|
|
style: TextStyle(
|
2026-04-29 11:40:17 +02:00
|
|
|
color: context.secondaryText.withValues(alpha: 0.7),
|
|
|
|
|
fontStyle: FontStyle.italic,
|
|
|
|
|
fontSize: 13,
|
2026-04-13 10:00:07 +02:00
|
|
|
),
|
2026-04-29 11:40:17 +02:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const Spacer(),
|
|
|
|
|
],
|
|
|
|
|
),
|
2026-04-13 10:00:07 +02:00
|
|
|
),
|
2026-04-09 19:25:32 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-29 11:40:17 +02:00
|
|
|
void _showStoreSelector(BuildContext context, ThemeData theme) {
|
|
|
|
|
showModalBottomSheet(
|
|
|
|
|
context: context,
|
|
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
|
|
|
|
|
),
|
|
|
|
|
builder: (context) {
|
|
|
|
|
// Leggiamo la lista dei negozi dal Cubit dedicato (se ce l'hai lì)
|
|
|
|
|
// Oppure adatta il blocco se li salvi altrove!
|
|
|
|
|
final staffState = context.watch<StaffCubit>().state;
|
|
|
|
|
final currentStoreId = context
|
|
|
|
|
.read<SessionCubit>()
|
|
|
|
|
.state
|
|
|
|
|
.currentStore
|
|
|
|
|
?.id;
|
|
|
|
|
final currentStaffId = context
|
|
|
|
|
.read<SessionCubit>()
|
|
|
|
|
.state
|
|
|
|
|
.currentStaffMember
|
|
|
|
|
?.id;
|
2026-04-20 16:52:20 +02:00
|
|
|
|
2026-04-29 11:40:17 +02:00
|
|
|
return SafeArea(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 24.0),
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
|
|
|
|
child: Text(
|
|
|
|
|
"Seleziona Negozio",
|
|
|
|
|
style: theme.textTheme.titleLarge?.copyWith(
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
if (staffState.status == StaffStatus.loading)
|
|
|
|
|
const Center(child: CircularProgressIndicator())
|
|
|
|
|
else if (staffState.storesByStaff[currentStaffId] == null)
|
|
|
|
|
const Padding(
|
|
|
|
|
padding: EdgeInsets.all(24.0),
|
|
|
|
|
child: Text("Nessun negozio disponibile."),
|
|
|
|
|
)
|
|
|
|
|
else
|
|
|
|
|
...staffState.storesByStaff[currentStaffId]!.map((store) {
|
|
|
|
|
final isSelected = store.id == currentStoreId;
|
|
|
|
|
return ListTile(
|
|
|
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
|
|
|
horizontal: 24.0,
|
|
|
|
|
),
|
|
|
|
|
leading: Icon(
|
|
|
|
|
Icons.storefront,
|
|
|
|
|
color: isSelected
|
|
|
|
|
? theme.colorScheme.primary
|
|
|
|
|
: theme.iconTheme.color,
|
|
|
|
|
),
|
|
|
|
|
title: Text(
|
|
|
|
|
store.nome,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontWeight: isSelected
|
|
|
|
|
? FontWeight.bold
|
|
|
|
|
: FontWeight.normal,
|
|
|
|
|
color: isSelected ? theme.colorScheme.primary : null,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
trailing: isSelected
|
|
|
|
|
? Icon(
|
|
|
|
|
Icons.check_circle,
|
|
|
|
|
color: theme.colorScheme.primary,
|
|
|
|
|
)
|
|
|
|
|
: null,
|
|
|
|
|
onTap: () {
|
|
|
|
|
// Cambiamo il negozio nel SessionCubit!
|
|
|
|
|
context.read<SessionCubit>().changeStore(store);
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
2026-04-16 11:50:29 +02:00
|
|
|
);
|
2026-04-09 19:25:32 +02:00
|
|
|
}
|
|
|
|
|
}
|