This commit is contained in:
2026-06-03 12:08:59 +02:00
parent 8ad2b7cf7e
commit a7fd37a894
9 changed files with 589 additions and 166 deletions

View File

@@ -89,12 +89,18 @@ class _AppMenuState extends State<AppMenu> {
Icon(Icons.bolt, color: theme.colorScheme.primary, size: 32), Icon(Icons.bolt, color: theme.colorScheme.primary, size: 32),
if (!effectivelyCollapsed) ...[ if (!effectivelyCollapsed) ...[
const SizedBox(width: 12), const SizedBox(width: 12),
Text( TextButton(
onPressed: () {
if (widget.isDrawer) Navigator.pop(context);
context.goNamed(Routes.home);
},
child: Text(
"FLUX", "FLUX",
style: theme.textTheme.titleLarge?.copyWith( style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
),
], ],
], ],
), ),
@@ -111,13 +117,36 @@ class _AppMenuState extends State<AppMenu> {
padding: const EdgeInsets.symmetric(horizontal: 8.0), padding: const EdgeInsets.symmetric(horizontal: 8.0),
children: [ children: [
_buildRouteItem( _buildRouteItem(
title: context.l10n.commonDashboard, title: 'Dashboard',
icon: Icons.dashboard_outlined, icon: Icons.dashboard_outlined,
routeName: Routes.home, // <--- Usiamo la tua costante! routeName: Routes.home,
pathToCheck: pathToCheck:
'/', // Il path da controllare per colorarlo '/', // Il path da controllare per colorarlo
isCollapsed: effectivelyCollapsed, isCollapsed: effectivelyCollapsed,
), ),
const SizedBox(height: 8),
// --- SEZIONE OPERATIVA ---
_buildHierarchicalItem(
title: 'Operatività',
icon: Icons.work_outline,
basePathToCheck: '/',
isCollapsed: effectivelyCollapsed,
subItems: [
_SubMenuItem(
'Operazioni',
Routes.operations,
'/operations',
),
_SubMenuItem(
'Assistenza',
Routes.tickets,
'/tickets',
),
_SubMenuItem('Tasks', Routes.tasks, '/tasks'),
_SubMenuItem('Sticky Notes', Routes.notes, '/notes'),
],
),
const SizedBox(height: 8), const SizedBox(height: 8),
// --- IL MENU GERARCHICO (ANAGRAFICHE) --- // --- IL MENU GERARCHICO (ANAGRAFICHE) ---
@@ -256,7 +285,9 @@ class _AppMenuState extends State<AppMenu> {
required bool isCollapsed, required bool isCollapsed,
required List<_SubMenuItem> subItems, required List<_SubMenuItem> subItems,
}) { }) {
final isSelected = widget.currentPath.startsWith(basePathToCheck); final isSelected = subItems.any(
(item) => widget.currentPath.startsWith(item.pathToCheck),
);
final theme = Theme.of(context); final theme = Theme.of(context);
if (isCollapsed) { if (isCollapsed) {

View File

@@ -1,6 +1,7 @@
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flux/core/blocs/session/session_cubit.dart'; import 'package:flux/core/blocs/session/session_cubit.dart';
import 'package:flux/core/enums_and_consts/consts.dart';
import 'package:get_it/get_it.dart'; import 'package:get_it/get_it.dart';
import 'package:supabase_flutter/supabase_flutter.dart'; // Per estrarre gli store import 'package:supabase_flutter/supabase_flutter.dart'; // Per estrarre gli store
import '../models/provider_model.dart'; import '../models/provider_model.dart';
@@ -32,7 +33,7 @@ class ProviderFormCubit extends Cubit<ProviderFormState> {
try { try {
// 1. Scarichiamo tutti i negozi dell'azienda // 1. Scarichiamo tutti i negozi dell'azienda
final storesResponse = await _client final storesResponse = await _client
.from('store') .from(Tables.stores)
.select('id, name') .select('id, name')
.eq('company_id', companyId); .eq('company_id', companyId);
@@ -41,7 +42,7 @@ class ProviderFormCubit extends Cubit<ProviderFormState> {
if (existingProvider != null && existingProvider.id != null) { if (existingProvider != null && existingProvider.id != null) {
// ... (Vecchio codice di recupero) // ... (Vecchio codice di recupero)
final links = await _client final links = await _client
.from('providers_in_stores') .from(Tables.providersInStores)
.select('store_id') .select('store_id')
.eq('provider_id', existingProvider.id!); .eq('provider_id', existingProvider.id!);
linkedStoreIds = (links as List) linkedStoreIds = (links as List)
@@ -83,6 +84,7 @@ class ProviderFormCubit extends Cubit<ProviderFormState> {
String? fiscalCode, String? fiscalCode,
String? sdiCode, String? sdiCode,
String? emailPec, String? emailPec,
String? Function()? colorHex,
}) { }) {
emit( emit(
state.copyWith( state.copyWith(
@@ -93,6 +95,7 @@ class ProviderFormCubit extends Cubit<ProviderFormState> {
fiscalCode: fiscalCode, fiscalCode: fiscalCode,
sdiCode: sdiCode, sdiCode: sdiCode,
emailPec: emailPec, emailPec: emailPec,
colorHex: colorHex,
), ),
), ),
); );

View File

@@ -1,4 +1,5 @@
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'provider_location_model.dart'; import 'provider_location_model.dart';
import 'provider_role.dart'; import 'provider_role.dart';
@@ -8,6 +9,7 @@ class ProviderModel extends Equatable {
final String companyId; final String companyId;
final String name; // Nome "commerciale" per riconoscerlo velocemente final String name; // Nome "commerciale" per riconoscerlo velocemente
final bool isActive; final bool isActive;
final String? colorHex;
// Dati fiscali e legali // Dati fiscali e legali
final String? businessName; // Ragione Sociale final String? businessName; // Ragione Sociale
@@ -29,6 +31,7 @@ class ProviderModel extends Equatable {
required this.companyId, required this.companyId,
required this.name, required this.name,
this.isActive = true, this.isActive = true,
this.colorHex,
this.businessName, this.businessName,
this.vatNumber, this.vatNumber,
this.fiscalCode, this.fiscalCode,
@@ -42,6 +45,17 @@ class ProviderModel extends Equatable {
this.locations, this.locations,
}); });
// 🥷 IL GETTER MAGICO: Converte l'esadecimale in un Color di Flutter
Color get displayColor {
if (colorHex == null || colorHex!.isEmpty) {
return Colors.blueGrey; // Colore di default
}
// Rimuove l'eventuale '#' e aggiunge 'FF' per l'opacità (Alpha)
final hex = colorHex!.replaceAll('#', '');
return Color(int.parse('FF$hex', radix: 16));
}
factory ProviderModel.empty({required String companyId}) { factory ProviderModel.empty({required String companyId}) {
return ProviderModel( return ProviderModel(
companyId: companyId, companyId: companyId,
@@ -56,6 +70,7 @@ class ProviderModel extends Equatable {
String? companyId, String? companyId,
String? name, String? name,
bool? isActive, bool? isActive,
String? Function()? colorHex,
String? businessName, String? businessName,
String? vatNumber, String? vatNumber,
String? fiscalCode, String? fiscalCode,
@@ -73,6 +88,7 @@ class ProviderModel extends Equatable {
companyId: companyId ?? this.companyId, companyId: companyId ?? this.companyId,
name: name ?? this.name, name: name ?? this.name,
isActive: isActive ?? this.isActive, isActive: isActive ?? this.isActive,
colorHex: colorHex != null ? colorHex() : this.colorHex,
businessName: businessName ?? this.businessName, businessName: businessName ?? this.businessName,
vatNumber: vatNumber ?? this.vatNumber, vatNumber: vatNumber ?? this.vatNumber,
fiscalCode: fiscalCode ?? this.fiscalCode, fiscalCode: fiscalCode ?? this.fiscalCode,
@@ -114,6 +130,7 @@ class ProviderModel extends Equatable {
companyId: map['company_id'] as String, companyId: map['company_id'] as String,
name: map['name'] as String, name: map['name'] as String,
isActive: map['is_active'] as bool? ?? true, isActive: map['is_active'] as bool? ?? true,
colorHex: map['color_hex'] as String?,
businessName: map['business_name'] as String?, businessName: map['business_name'] as String?,
vatNumber: map['vat_number'] as String?, vatNumber: map['vat_number'] as String?,
fiscalCode: map['fiscal_code'] as String?, fiscalCode: map['fiscal_code'] as String?,
@@ -134,6 +151,7 @@ class ProviderModel extends Equatable {
'company_id': companyId, 'company_id': companyId,
'name': name, 'name': name,
'is_active': isActive, 'is_active': isActive,
'color_hex': colorHex,
'business_name': businessName, 'business_name': businessName,
'vat_number': vatNumber, 'vat_number': vatNumber,
'fiscal_code': fiscalCode, 'fiscal_code': fiscalCode,
@@ -155,6 +173,7 @@ class ProviderModel extends Equatable {
companyId, companyId,
name, name,
isActive, isActive,
colorHex,
businessName, businessName,
vatNumber, vatNumber,
fiscalCode, fiscalCode,

View File

@@ -66,6 +66,17 @@ class _ProviderFormScreenState extends State<ProviderFormScreen> {
super.dispose(); super.dispose();
} }
final List<String> _brandColors = [
'#E60000', // Vodafone/Iliad (Rosso scuro)
'#0047BB', // TIM (Blu)
'#F4811F', // WINDTRE (Arancione)
'#FFCC00', // Fastweb (Giallo)
'#00A859', // Verde generico
'#8E44AD', // Viola
'#2C3E50', // Blu scuro/Nero
'#607D8B', // BlueGrey (Default)
];
void _flushControllers() { void _flushControllers() {
context.read<ProviderFormCubit>().updateFields( context.read<ProviderFormCubit>().updateFields(
name: _nameCtrl.text.trim(), name: _nameCtrl.text.trim(),
@@ -132,6 +143,8 @@ class _ProviderFormScreenState extends State<ProviderFormScreen> {
children: [ children: [
_buildGeneralCard(context, state), _buildGeneralCard(context, state),
const SizedBox(height: 24), const SizedBox(height: 24),
_buildColorPicker(),
const SizedBox(height: 24),
_buildRolesCard(context, state), _buildRolesCard(context, state),
const SizedBox(height: 24), const SizedBox(height: 24),
_buildFiscalCard(context), _buildFiscalCard(context),
@@ -392,4 +405,70 @@ class _ProviderFormScreenState extends State<ProviderFormScreen> {
), ),
); );
} }
Widget _buildColorPicker() {
return Column(
children: [
const Text(
'Colore Riconoscitivo',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
const SizedBox(height: 12),
BlocBuilder<ProviderFormCubit, ProviderFormState>(
builder: (context, state) {
// Se non ha un colore, usiamo il BlueGrey di default
final currentColorHex = state.provider?.colorHex ?? '#607D8B';
return Wrap(
spacing: 12,
runSpacing: 12,
children: _brandColors.map((hexCode) {
final isSelected =
currentColorHex.toUpperCase() == hexCode.toUpperCase();
// Conversione rapida per disegnare il cerchio
final colorValue = Color(
int.parse('FF${hexCode.replaceAll('#', '')}', radix: 16),
);
return InkWell(
borderRadius: BorderRadius.circular(24),
onTap: () {
// Aggiorniamo il Cubit con il nuovo colore
context.read<ProviderFormCubit>().updateFields(
colorHex: () => hexCode,
);
},
child: AnimatedContainer(
duration: const Duration(milliseconds: 200),
width: 42,
height: 42,
decoration: BoxDecoration(
color: colorValue,
shape: BoxShape.circle,
border: Border.all(
color: isSelected ? Colors.black : Colors.transparent,
width: isSelected ? 3 : 0,
),
boxShadow: [
if (isSelected)
BoxShadow(
color: colorValue.withValues(alpha: 0.4),
blurRadius: 8,
spreadRadius: 2,
),
],
),
child: isSelected
? const Icon(Icons.check, color: Colors.white, size: 24)
: null,
),
);
}).toList(),
);
},
),
],
);
}
} }

View File

@@ -98,17 +98,23 @@ class OperationFormCubit extends Cubit<OperationFormState> {
emit( emit(
state.copyWith( state.copyWith(
status: OperationFormStatus.ready, // Torna ready per il nuovo form status: OperationFormStatus.ready,
operation: OperationModel( operation: OperationModel(
companyId: current.companyId, companyId: current.companyId,
storeId: current.storeId, storeId: current.storeId,
storeDisplayName: current.storeDisplayName, storeDisplayName: current.storeDisplayName,
batchUuid: current.batchUuid, // MANTIENE IL COLLEGAMENTO // 🥷 REINSERIAMO LO STAFF (Il "colpevole" era qui)
customerId: current.customerId, // MANTIENE IL CLIENTE staffId: current.staffId,
staffDisplayName: current.staffDisplayName,
batchUuid: current.batchUuid,
customerId: current.customerId,
customer: current.customer, customer: current.customer,
reference: current.reference, reference: current.reference,
status: OperationStatus.draft, status: OperationStatus.draft,
createdAt: DateTime.now(), createdAt: DateTime.now(),
// Mantieni isBusiness se vuoi che rimanga coerente col cliente
isBusiness: current.isBusiness,
), ),
), ),
); );
@@ -213,7 +219,7 @@ class OperationFormCubit extends Cubit<OperationFormState> {
String? type, String? type,
String? providerId, String? providerId,
String? providerDisplayName, String? providerDisplayName,
String? subtype, String? subType,
String? description, String? description,
DateTime? expirationDate, DateTime? expirationDate,
int? quantity, int? quantity,
@@ -226,7 +232,7 @@ class OperationFormCubit extends Cubit<OperationFormState> {
bool clearProvider = false, bool clearProvider = false,
bool clearType = false, bool clearType = false,
bool clearSubtype = false, bool clearSubType = false,
bool clearDescription = false, bool clearDescription = false,
bool clearExpiration = false, bool clearExpiration = false,
bool clearQuantity = false, bool clearQuantity = false,
@@ -251,7 +257,7 @@ class OperationFormCubit extends Cubit<OperationFormState> {
description: clearDescription description: clearDescription
? null ? null
: (description ?? current.description), : (description ?? current.description),
subtype: clearSubtype ? null : (subtype ?? current.subtype), subType: clearSubType ? null : (subType ?? current.subType),
expirationDate: clearExpiration expirationDate: clearExpiration
? null ? null
: (expirationDate ?? current.expirationDate), : (expirationDate ?? current.expirationDate),
@@ -287,7 +293,7 @@ class OperationFormCubit extends Cubit<OperationFormState> {
}) { }) {
// 1. Aggiorniamo il tipo nel modello in canna // 1. Aggiorniamo il tipo nel modello in canna
// (Presumo tu abbia un metodo copyWith o simile) // (Presumo tu abbia un metodo copyWith o simile)
final updatedOp = state.operation.copyWith(type: newType, subtype: ''); final updatedOp = state.operation.copyWith(type: newType, subType: '');
// 2. Prepariamoci ad auto-selezionare il provider // 2. Prepariamoci ad auto-selezionare il provider
String? newProviderId = updatedOp.providerId; String? newProviderId = updatedOp.providerId;
@@ -389,7 +395,7 @@ class OperationFormCubit extends Cubit<OperationFormState> {
state.copyWith( state.copyWith(
operation: currentOp.copyWith( operation: currentOp.copyWith(
type: newType, type: newType,
subtype: subType:
'', // Resettiamo il sottotipo per evitare incongruenze (es. passo da Luce a DAZN) '', // Resettiamo il sottotipo per evitare incongruenze (es. passo da Luce a DAZN)
expirationDate: expirationDate:
defaultDate, // Impostiamo la scadenza di default se calcolata defaultDate, // Impostiamo la scadenza di default se calcolata

View File

@@ -28,7 +28,7 @@ class OperationModel extends Equatable {
final String? id; final String? id;
final DateTime? createdAt; final DateTime? createdAt;
final String type; final String type;
final String? subtype; final String? subType;
final String? providerId; final String? providerId;
final String? providerDisplayName; final String? providerDisplayName;
final String? modelId; final String? modelId;
@@ -58,7 +58,7 @@ class OperationModel extends Equatable {
this.id, this.id,
this.createdAt, this.createdAt,
this.type = '', this.type = '',
this.subtype, this.subType,
this.providerId, this.providerId,
this.providerDisplayName, this.providerDisplayName,
this.modelId, this.modelId,
@@ -87,7 +87,7 @@ class OperationModel extends Equatable {
String? id, String? id,
DateTime? createdAt, DateTime? createdAt,
String? type, String? type,
String? subtype, String? subType,
String? providerId, String? providerId,
String? providerDisplayName, String? providerDisplayName,
String? modelId, String? modelId,
@@ -114,7 +114,7 @@ class OperationModel extends Equatable {
id: id ?? this.id, id: id ?? this.id,
createdAt: createdAt ?? this.createdAt, createdAt: createdAt ?? this.createdAt,
type: type ?? this.type, type: type ?? this.type,
subtype: subtype ?? this.subtype, subType: subType ?? this.subType,
providerId: providerId ?? this.providerId, providerId: providerId ?? this.providerId,
providerDisplayName: providerDisplayName ?? this.providerDisplayName, providerDisplayName: providerDisplayName ?? this.providerDisplayName,
modelId: modelId ?? this.modelId, modelId: modelId ?? this.modelId,
@@ -144,7 +144,7 @@ class OperationModel extends Equatable {
id, id,
createdAt, createdAt,
type, type,
subtype, subType,
providerId, providerId,
providerDisplayName, providerDisplayName,
modelId, modelId,
@@ -180,7 +180,7 @@ class OperationModel extends Equatable {
? DateTime.parse(map['created_at']) ? DateTime.parse(map['created_at'])
: null, : null,
type: map['type'] as String? ?? '', type: map['type'] as String? ?? '',
subtype: map['sub_type'] as String?, subType: map['sub_type'] as String?,
// I campi relazionali nullabili restano rigorosamente null! // I campi relazionali nullabili restano rigorosamente null!
providerId: map['provider_id'] as String?, providerId: map['provider_id'] as String?,
@@ -237,7 +237,7 @@ class OperationModel extends Equatable {
return { return {
if (id != null) 'id': id, if (id != null) 'id': id,
'type': type, 'type': type,
'sub_type': subtype, 'sub_type': subType,
'provider_id': providerId, 'provider_id': providerId,
'model_id': modelId, 'model_id': modelId,
'description': description, 'description': description,

View File

@@ -79,7 +79,7 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
_noteController.text = model.note; _noteController.text = model.note;
} }
if (_freeTextSubtypeController.text.isEmpty) { if (_freeTextSubtypeController.text.isEmpty) {
_freeTextSubtypeController.text = model.subtype ?? ''; _freeTextSubtypeController.text = model.subType ?? '';
} }
if (_freeTextDescriptionController.text.isEmpty) { if (_freeTextDescriptionController.text.isEmpty) {
_freeTextDescriptionController.text = model.description ?? ''; _freeTextDescriptionController.text = model.description ?? '';
@@ -91,7 +91,7 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
context.read<OperationFormCubit>().updateFields( context.read<OperationFormCubit>().updateFields(
reference: _referenceController.text, reference: _referenceController.text,
note: _noteController.text, note: _noteController.text,
subtype: _freeTextSubtypeController.text, subType: _freeTextSubtypeController.text,
description: _freeTextDescriptionController.text, description: _freeTextDescriptionController.text,
); );
} }

View File

@@ -1,12 +1,9 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flux/core/routes/routes.dart'; import 'package:flux/core/routes/routes.dart';
import 'package:flux/core/widgets/staff_selector_modal.dart';
import 'package:flux/features/master_data/staff/models/staff_member_model.dart';
import 'package:flux/features/operations/blocs/operation_list_cubit.dart'; import 'package:flux/features/operations/blocs/operation_list_cubit.dart';
import 'package:flux/features/operations/models/operation_model.dart'; import 'package:flux/features/operations/models/operation_model.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
// Importa i tuoi modelli e cubit
class OperationListScreen extends StatefulWidget { class OperationListScreen extends StatefulWidget {
const OperationListScreen({super.key}); const OperationListScreen({super.key});
@@ -18,10 +15,13 @@ class OperationListScreen extends StatefulWidget {
class _OperationListScreenState extends State<OperationListScreen> { class _OperationListScreenState extends State<OperationListScreen> {
final ScrollController _scrollController = ScrollController(); final ScrollController _scrollController = ScrollController();
// 🥷 1. LO STATO PER LE BULK ACTIONS
final Set<String> _selectedOperationIds = {};
bool get _isSelectionMode => _selectedOperationIds.isNotEmpty;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
// Agganciamo il listener per la paginazione (Scroll Infinito)
_scrollController.addListener(_onScroll); _scrollController.addListener(_onScroll);
} }
@@ -35,7 +35,6 @@ class _OperationListScreenState extends State<OperationListScreen> {
if (!_scrollController.hasClients) return false; if (!_scrollController.hasClients) return false;
final maxScroll = _scrollController.position.maxScrollExtent; final maxScroll = _scrollController.position.maxScrollExtent;
final currentScroll = _scrollController.offset; final currentScroll = _scrollController.offset;
// Carica quando mancano 200px alla fine
return currentScroll >= (maxScroll * 0.9); return currentScroll >= (maxScroll * 0.9);
} }
@@ -45,99 +44,263 @@ class _OperationListScreenState extends State<OperationListScreen> {
super.dispose(); super.dispose();
} }
void _toggleSelection(String id) {
setState(() {
if (_selectedOperationIds.contains(id)) {
_selectedOperationIds.remove(id);
} else {
_selectedOperationIds.add(id);
}
});
}
void _clearSelection() {
setState(() {
_selectedOperationIds.clear();
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( // 🥷 2. APPBAR DINAMICA (Standard o Modalità Selezione)
appBar: _isSelectionMode
? AppBar(
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
leading: IconButton(
icon: const Icon(Icons.close),
onPressed: _clearSelection,
),
title: Text("${_selectedOperationIds.length} selezionate"),
actions: [
IconButton(
icon: const Icon(Icons.edit_note),
tooltip: 'Cambia Stato Massivo',
onPressed: () {
// TODO: Apri BottomSheet per cambiare stato a tutte le selezionate
},
),
],
)
: AppBar(
title: const Text("Gestione Servizi"), title: const Text("Gestione Servizi"),
elevation: 0, elevation: 0,
actions: [ actions: [
IconButton( IconButton(
icon: const Icon(Icons.search), icon: const Icon(Icons.filter_list),
onPressed: () { onPressed: () {
// Qui potrai implementare una barra di ricerca // TODO: Apri drawer laterale o modal per i filtri avanzati
}, },
), ),
IconButton(icon: const Icon(Icons.search), onPressed: () {}),
], ],
), ),
body: BlocBuilder<OperationListCubit, OperationListState>( body: BlocBuilder<OperationListCubit, OperationListState>(
builder: (context, state) { builder: (context, state) {
// 1. Stato di caricamento iniziale
if (state.status == OperationListStatus.loading && if (state.status == OperationListStatus.loading &&
state.operations.isEmpty) { state.operations.isEmpty) {
return const Center(child: CircularProgressIndicator()); return const Center(child: CircularProgressIndicator());
} }
// 2. Lista vuota
if (state.operations.isEmpty) { if (state.operations.isEmpty) {
return Center( return const Center(child: Text("Nessuna pratica trovata."));
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("Nessuna pratica trovata."),
const SizedBox(height: 10),
ElevatedButton(
onPressed: () => context
.read<OperationListCubit>()
.loadOperations(refresh: true),
child: const Text("Riprova"),
),
],
),
);
} }
// 3. La Lista (con Pull-to-refresh) // 🥷 3. IL MOTORE RESPONSIVO
return RefreshIndicator( return RefreshIndicator(
onRefresh: () => context.read<OperationListCubit>().loadOperations( onRefresh: () => context.read<OperationListCubit>().loadOperations(
refresh: true, refresh: true,
), ),
child: ListView.builder( child: LayoutBuilder(
builder: (context, constraints) {
// Se lo schermo è largo (Desktop/Tablet), usiamo la griglia
final isDesktop = constraints.maxWidth > 700;
return GridView.builder(
controller: _scrollController, controller: _scrollController,
padding: const EdgeInsets.only(bottom: 80), // Spazio per il FAB padding: const EdgeInsets.all(12).copyWith(bottom: 80),
// Magia della griglia: si adatta!
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent:
450, // Larghezza massima della singola card
mainAxisExtent:
180, // Altezza fissa della card (da aggiustare in base ai tuoi font)
crossAxisSpacing: 12,
mainAxisSpacing: 12,
),
itemCount: state.hasReachedMax itemCount: state.hasReachedMax
? state.operations.length ? state.operations.length
: state.operations.length + 1, : state.operations.length + 1,
itemBuilder: (context, index) { itemBuilder: (context, index) {
if (index >= state.operations.length) { if (index >= state.operations.length) {
return const Center( return const Center(
child: Padding(
padding: EdgeInsets.all(16.0),
child: CircularProgressIndicator(strokeWidth: 2), child: CircularProgressIndicator(strokeWidth: 2),
),
); );
} }
final operation = state.operations[index]; final operation = state.operations[index];
return _buildOperationCard(context, operation); final isSelected = _selectedOperationIds.contains(
}, operation.id,
),
); );
},
), return _RichOperationCard(
floatingActionButton: FloatingActionButton( operation: operation,
onPressed: () async { isSelected: isSelected,
StaffMemberModel? createdBy = await getStaffMember(context); isSelectionMode: _isSelectionMode,
if (createdBy == null || !context.mounted) return; onTap: () {
if (_isSelectionMode) {
_toggleSelection(operation.id!);
} else {
context.pushNamed( context.pushNamed(
Routes.operationForm, Routes.operationForm,
pathParameters: {'id': 'new'}, extra: (createdBy: null, operation: operation),
extra: (createdBy: createdBy, operation: null), pathParameters: {'id': operation.id!},
); );
}
},
onLongPress: () => _toggleSelection(operation.id!),
);
},
);
},
),
);
},
),
floatingActionButton: _isSelectionMode
? null // Nascondi il FAB se stai selezionando
: FloatingActionButton(
onPressed: () {
/* Tuo codice per nuova operazione */
}, },
child: const Icon(Icons.add), child: const Icon(Icons.add),
), ),
); );
} }
}
// 🥷 4. LA SUPER CARD ESTRATTA
class _RichOperationCard extends StatelessWidget {
final OperationModel operation;
final bool isSelected;
final bool isSelectionMode;
final VoidCallback onTap;
final VoidCallback onLongPress;
const _RichOperationCard({
required this.operation,
required this.isSelected,
required this.isSelectionMode,
required this.onTap,
required this.onLongPress,
});
// 🥷 1. IL COLORE DELLO STATO: Centralizzato per usarlo ovunque
Color _getStatusColor(OperationStatus status) {
switch (status) {
case OperationStatus.success:
return Colors.green;
case OperationStatus.waitingForAction:
case OperationStatus.draft:
return Colors.orange;
case OperationStatus.waitingForSupport:
return Colors.blue;
case OperationStatus.failure:
return Colors.grey.shade800; // O Colors.red se preferisci
}
}
// 🥷 2. IL COLORE DEL TIPO: Per farlo risaltare
Color _getTypeColor(String type) {
switch (type) {
case 'FIN':
return Colors.deepPurple;
case 'TELEPASS':
return Colors.yellow.shade700;
case 'ENERGY':
return Colors.amber.shade700;
case 'ENTERTAINMENT':
return Colors.pinkAccent;
case 'AL':
case 'MNP':
return Colors.indigo;
case 'NIP':
case 'FWA':
return Colors.cyan;
default:
return Colors.blueGrey;
}
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final statusColor = _getStatusColor(operation.status);
final typeColor = _getTypeColor(operation.type);
Widget _buildOperationCard(BuildContext context, OperationModel operation) {
return Card( return Card(
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 6), elevation: isSelected ? 4 : 1,
elevation: 2, shape: RoundedRectangleBorder(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), borderRadius: BorderRadius.circular(12),
child: ListTile( side: BorderSide(
contentPadding: const EdgeInsets.all(12), color: isSelected ? theme.colorScheme.primary : Colors.transparent,
title: Row( width: 2,
),
),
child: InkWell(
borderRadius: BorderRadius.circular(12),
onTap: onTap,
onLongPress: onLongPress,
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: Container(
decoration: BoxDecoration(
color: isSelected
? theme.colorScheme.primaryContainer.withValues(alpha: 0.2)
: null,
// BANDA LATERALE LEGATA ALLO STATO (Stilosissima)
border: Border(left: BorderSide(color: statusColor, width: 6)),
),
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// --- HEADER ---
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
if (isSelectionMode)
SizedBox(
height: 24,
width: 24,
child: Checkbox(
value: isSelected,
onChanged: (_) => onTap(),
),
),
Expanded(
child: Text(
operation.reference ?? 'Senza Riferimento',
style: theme.textTheme.labelSmall?.copyWith(
color: Colors.grey[600],
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
Text(
"${operation.createdAt?.day.toString().padLeft(2, '0')}/${operation.createdAt?.month.toString().padLeft(2, '0')}/${operation.createdAt?.year}",
style: theme.textTheme.labelSmall?.copyWith(
color: Colors.grey[600],
),
),
],
),
const SizedBox(height: 8),
// --- CLIENTE E TIPO OPERAZIONE ---
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Expanded( Expanded(
child: Text( child: Text(
@@ -146,61 +309,183 @@ class _OperationListScreenState extends State<OperationListScreen> {
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 16, fontSize: 16,
), ),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 8),
// IL TIPO DI OPERAZIONE CHE SPICCA
Container(
padding: const EdgeInsets.symmetric(
horizontal: 10,
vertical: 6,
),
decoration: BoxDecoration(
color: typeColor.withValues(alpha: 0.15),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: typeColor.withValues(alpha: 0.3),
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (_getIconForType(
operation.type,
operation.subType,
) !=
null) ...[
Icon(
_getIconForType(
operation.type,
operation.subType,
),
size: 14,
color: typeColor,
),
const SizedBox(width: 4),
],
Text(
operation.subType?.isNotEmpty == true
? operation.subType!
: operation.type,
style: TextStyle(
color: typeColor,
fontWeight: FontWeight.bold,
fontSize: 12,
), ),
), ),
], ],
), ),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 4),
Text(
"Pratica: ${operation.reference}${operation.createdAt?.day}/${operation.createdAt?.month}/${operation.createdAt?.year}",
), ),
const SizedBox(height: 8), ],
),
const SizedBox(height: 12),
// --- I TAG COMPATTI (Business/Privato, Provider, Device) ---
Wrap(
spacing: 6,
runSpacing: 6,
children: [
// Espanso in "Business" e "Privato"
_MiniChip(
label: operation.isBusiness ? 'Business' : 'Privato',
icon: operation.isBusiness
? Icons.business
: Icons.person,
color: operation.isBusiness ? Colors.indigo : Colors.teal,
),
// Tag Provider con il suo colore personalizzato dal DB
if (operation.providerId != null)
_MiniChip(
label: operation.providerDisplayName ?? 'Gestore',
// Se hai popolato il campo colorHex, qui puoi usare: operation.provider?.displayColor ?? Colors.grey
color: Colors.redAccent,
),
if (operation.type == 'Fin' && operation.modelId != null)
_MiniChip(
label: operation.modelDisplayName ?? 'Modello',
icon: Icons.devices,
color: Colors.deepPurple,
),
],
),
const Spacer(),
// --- FOOTER: Staff e Stato ---
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row( Row(
children: [ children: [
Text(operation.type), const Icon(
const SizedBox(width: 8), Icons.support_agent,
_buildOperationStatus(operation.status), size: 14,
color: Colors.grey,
),
const SizedBox(width: 4),
Text(
operation.staffDisplayName ?? 'Staff',
style: theme.textTheme.labelSmall?.copyWith(
color: Colors.grey[700],
),
),
],
),
_buildOperationStatus(operation.status, statusColor),
], ],
), ),
], ],
), ),
trailing: const Icon(Icons.chevron_right), ),
onTap: () => context.pushNamed(
Routes.operationForm,
extra: (createdBy: null, operation: operation),
pathParameters: {'id': operation.id!},
), ),
), ),
); );
} }
Widget _buildOperationStatus(OperationStatus status) { IconData? _getIconForType(String type, String? subtype) {
Color color; if (type == 'Energy') {
switch (status) { if (subtype?.toLowerCase() == 'luce') return Icons.bolt;
case OperationStatus.failure: if (subtype?.toLowerCase() == 'gas') return Icons.local_fire_department;
color = Colors.grey.shade800;
break;
case OperationStatus.waitingForAction || OperationStatus.draft:
color = Colors.orange;
break;
case OperationStatus.success:
color = Colors.green;
break;
case OperationStatus.waitingForSupport:
color = Colors.blue;
break;
} }
return Chip( return null;
label: Text("BOZZA", style: TextStyle(fontSize: 10, color: Colors.white)),
backgroundColor: color,
visualDensity: VisualDensity.compact,
);
} }
void startNewOperation(BuildContext context) { Widget _buildOperationStatus(OperationStatus status, Color statusColor) {
context.pushNamed('operation-form', pathParameters: {'id': 'new'}); return Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: statusColor,
borderRadius: BorderRadius.circular(8),
),
child: Text(
status.displayName,
style: const TextStyle(
fontSize: 10,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
);
}
}
class _MiniChip extends StatelessWidget {
final String label;
final IconData? icon;
final Color color;
const _MiniChip({required this.label, this.icon, required this.color});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 4),
decoration: BoxDecoration(
color: color.withValues(alpha: 0.1),
border: Border.all(color: color.withValues(alpha: 0.3)),
borderRadius: BorderRadius.circular(6),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (icon != null) ...[
Icon(icon, size: 12, color: color),
const SizedBox(width: 4),
],
Text(
label,
style: TextStyle(
fontSize: 11,
color: color,
fontWeight: FontWeight.bold,
),
),
],
),
);
} }
} }

View File

@@ -164,8 +164,8 @@ class OperationDetailsSection extends StatelessWidget {
if (currentType == 'Energy') ...[ if (currentType == 'Energy') ...[
DropdownButtonFormField<String>( DropdownButtonFormField<String>(
initialValue: initialValue:
(currentOp?.subtype != null && currentOp!.subtype!.isNotEmpty) (currentOp?.subType != null && currentOp!.subType!.isNotEmpty)
? currentOp!.subtype ? currentOp!.subType
: null, : null,
decoration: const InputDecoration(labelText: 'Dettaglio Fornitura'), decoration: const InputDecoration(labelText: 'Dettaglio Fornitura'),
items: [ items: [
@@ -174,7 +174,7 @@ class OperationDetailsSection extends StatelessWidget {
].map((s) => DropdownMenuItem(value: s, child: Text(s))).toList(), ].map((s) => DropdownMenuItem(value: s, child: Text(s))).toList(),
onChanged: (val) { onChanged: (val) {
if (val != null) { if (val != null) {
context.read<OperationFormCubit>().updateFields(subtype: val); context.read<OperationFormCubit>().updateFields(subType: val);
} }
}, },
), ),