2026-04-16 11:50:29 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2026-05-13 15:41:35 +02:00
|
|
|
import 'package:flux/core/routes/routes.dart';
|
2026-06-03 19:16:15 +02:00
|
|
|
import 'package:flux/core/widgets/staff_selector_modal.dart';
|
|
|
|
|
import 'package:flux/features/master_data/staff/models/staff_member_model.dart';
|
2026-05-08 12:28:14 +02:00
|
|
|
import 'package:flux/features/operations/blocs/operation_list_cubit.dart';
|
2026-05-04 15:36:42 +02:00
|
|
|
import 'package:flux/features/operations/models/operation_model.dart';
|
2026-04-16 11:50:29 +02:00
|
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
|
|
2026-05-08 12:28:14 +02:00
|
|
|
class OperationListScreen extends StatefulWidget {
|
|
|
|
|
const OperationListScreen({super.key});
|
2026-04-16 11:50:29 +02:00
|
|
|
|
|
|
|
|
@override
|
2026-05-08 12:28:14 +02:00
|
|
|
State<OperationListScreen> createState() => _OperationListScreenState();
|
2026-04-16 11:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
2026-05-08 12:28:14 +02:00
|
|
|
class _OperationListScreenState extends State<OperationListScreen> {
|
2026-04-16 11:50:29 +02:00
|
|
|
final ScrollController _scrollController = ScrollController();
|
2026-06-03 19:16:15 +02:00
|
|
|
final TextEditingController _searchController = TextEditingController();
|
2026-04-16 11:50:29 +02:00
|
|
|
|
2026-06-03 19:16:15 +02:00
|
|
|
// Set per gestire le Bulk Actions (Selezione multipla)
|
2026-06-03 12:08:59 +02:00
|
|
|
final Set<String> _selectedOperationIds = {};
|
|
|
|
|
bool get _isSelectionMode => _selectedOperationIds.isNotEmpty;
|
|
|
|
|
|
2026-06-03 19:16:15 +02:00
|
|
|
// Flag per mostrare/nascondere la barra di ricerca integrata nell'AppBar
|
|
|
|
|
bool _showSearchBar = false;
|
|
|
|
|
|
2026-04-16 11:50:29 +02:00
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_scrollController.addListener(_onScroll);
|
2026-06-03 19:16:15 +02:00
|
|
|
|
|
|
|
|
// Primo caricamento: partiamo da pagina 1
|
|
|
|
|
// (Il Cubit deciderà se fare il boot iniziale o se c'era già roba in cache)
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
|
final isDesktop = MediaQuery.sizeOf(context).width >= 900;
|
|
|
|
|
if (isDesktop) {
|
|
|
|
|
context.read<OperationListCubit>().loadSpecificPageDesktop(1);
|
|
|
|
|
} else {
|
|
|
|
|
context.read<OperationListCubit>().loadNextPageMobile(refresh: true);
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-04-16 11:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _onScroll() {
|
2026-06-03 19:16:15 +02:00
|
|
|
final isDesktop = MediaQuery.sizeOf(context).width >= 900;
|
|
|
|
|
// 🥷 COMPORTAMENTO IBRIDO: Lo scroll infinito si attiva SOLO su mobile
|
|
|
|
|
if (isDesktop) return;
|
|
|
|
|
|
2026-04-16 11:50:29 +02:00
|
|
|
if (_isBottom) {
|
2026-06-03 19:16:15 +02:00
|
|
|
context.read<OperationListCubit>().loadNextPageMobile();
|
2026-04-16 11:50:29 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool get _isBottom {
|
|
|
|
|
if (!_scrollController.hasClients) return false;
|
|
|
|
|
final maxScroll = _scrollController.position.maxScrollExtent;
|
|
|
|
|
final currentScroll = _scrollController.offset;
|
|
|
|
|
return currentScroll >= (maxScroll * 0.9);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_scrollController.dispose();
|
2026-06-03 19:16:15 +02:00
|
|
|
_searchController.dispose();
|
2026-04-16 11:50:29 +02:00
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-03 12:08:59 +02:00
|
|
|
void _toggleSelection(String id) {
|
|
|
|
|
setState(() {
|
|
|
|
|
if (_selectedOperationIds.contains(id)) {
|
|
|
|
|
_selectedOperationIds.remove(id);
|
|
|
|
|
} else {
|
|
|
|
|
_selectedOperationIds.add(id);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _clearSelection() {
|
|
|
|
|
setState(() {
|
|
|
|
|
_selectedOperationIds.clear();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-16 11:50:29 +02:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2026-06-03 19:16:15 +02:00
|
|
|
final isDesktop = MediaQuery.sizeOf(context).width >= 900;
|
|
|
|
|
|
2026-04-16 11:50:29 +02:00
|
|
|
return Scaffold(
|
2026-06-03 19:16:15 +02:00
|
|
|
// --- APP BAR DINAMICA E INTEGRATA ---
|
2026-06-03 12:08:59 +02:00
|
|
|
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: () {
|
2026-06-03 19:16:15 +02:00
|
|
|
// TODO: Integrare bottom sheet per azioni massive
|
2026-06-03 12:08:59 +02:00
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
: AppBar(
|
2026-06-03 19:16:15 +02:00
|
|
|
title: _showSearchBar
|
|
|
|
|
? TextField(
|
|
|
|
|
controller: _searchController,
|
|
|
|
|
autofocus: true,
|
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
|
hintText: 'Cerca per cliente, nota o riferimento...',
|
|
|
|
|
border: InputBorder.none,
|
|
|
|
|
),
|
|
|
|
|
style: const TextStyle(fontSize: 16),
|
|
|
|
|
onChanged: (text) {
|
|
|
|
|
context.read<OperationListCubit>().updateFilters(
|
|
|
|
|
text: text,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
: const Text("Gestione Servizi"),
|
2026-06-03 12:08:59 +02:00
|
|
|
elevation: 0,
|
|
|
|
|
actions: [
|
|
|
|
|
IconButton(
|
2026-06-03 19:16:15 +02:00
|
|
|
icon: Icon(_showSearchBar ? Icons.close : Icons.search),
|
2026-06-03 12:08:59 +02:00
|
|
|
onPressed: () {
|
2026-06-03 19:16:15 +02:00
|
|
|
setState(() {
|
|
|
|
|
_showSearchBar = !_showSearchBar;
|
|
|
|
|
if (!_showSearchBar) {
|
|
|
|
|
_searchController.clear();
|
|
|
|
|
context.read<OperationListCubit>().clearFilters();
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-06-03 12:08:59 +02:00
|
|
|
},
|
|
|
|
|
),
|
2026-06-03 19:16:15 +02:00
|
|
|
if (!isDesktop) // Il pull-to-refresh c'è già su mobile, su desktop mettiamo un tasto manuale
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: const Icon(Icons.filter_list),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
// TODO: Bottone Filtri Avanzati (es. DateRange Picker)
|
|
|
|
|
},
|
|
|
|
|
),
|
2026-06-03 12:08:59 +02:00
|
|
|
],
|
|
|
|
|
),
|
2026-06-03 19:16:15 +02:00
|
|
|
|
|
|
|
|
// --- CORPO RESPONSIVO ---
|
2026-05-08 12:28:14 +02:00
|
|
|
body: BlocBuilder<OperationListCubit, OperationListState>(
|
2026-04-16 11:50:29 +02:00
|
|
|
builder: (context, state) {
|
2026-05-08 12:28:14 +02:00
|
|
|
if (state.status == OperationListStatus.loading &&
|
|
|
|
|
state.operations.isEmpty) {
|
2026-04-16 11:50:29 +02:00
|
|
|
return const Center(child: CircularProgressIndicator());
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-08 12:28:14 +02:00
|
|
|
if (state.operations.isEmpty) {
|
2026-06-03 19:16:15 +02:00
|
|
|
return Center(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
const Text("Nessuna pratica trovata."),
|
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: () => isDesktop
|
|
|
|
|
? context
|
|
|
|
|
.read<OperationListCubit>()
|
|
|
|
|
.loadSpecificPageDesktop(1)
|
|
|
|
|
: context.read<OperationListCubit>().loadNextPageMobile(
|
|
|
|
|
refresh: true,
|
|
|
|
|
),
|
|
|
|
|
child: const Text("Ricarica"),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
2026-04-16 11:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
2026-06-03 19:16:15 +02:00
|
|
|
// 🥷 SCENARIO DESKTOP: Griglia + Barra di Paginazione Gmail-Style
|
|
|
|
|
if (isDesktop) {
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: GridView.builder(
|
|
|
|
|
controller: _scrollController,
|
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
|
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
|
|
|
|
maxCrossAxisExtent:
|
|
|
|
|
420, // Larghezza bilanciata per le card su desktop
|
|
|
|
|
mainAxisExtent:
|
|
|
|
|
175, // Altezza controllata per evitare buchi bianchi
|
|
|
|
|
crossAxisSpacing: 16,
|
|
|
|
|
mainAxisSpacing: 16,
|
|
|
|
|
),
|
|
|
|
|
itemCount: state.operations.length,
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
final operation = state.operations[index];
|
|
|
|
|
return _buildResponsiveCard(operation);
|
|
|
|
|
},
|
2026-06-03 12:08:59 +02:00
|
|
|
),
|
2026-06-03 19:16:15 +02:00
|
|
|
),
|
|
|
|
|
_buildDesktopPaginationFooter(
|
|
|
|
|
state,
|
|
|
|
|
), // La barra in fondo stile Gmail
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 🥷 SCENARIO MOBILE: ListView con Infinite Scroll e Pull-to-Refresh
|
|
|
|
|
return RefreshIndicator(
|
|
|
|
|
onRefresh: () => context
|
|
|
|
|
.read<OperationListCubit>()
|
|
|
|
|
.loadNextPageMobile(refresh: true),
|
|
|
|
|
child: ListView.builder(
|
|
|
|
|
controller: _scrollController,
|
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
|
bottom: 80,
|
|
|
|
|
left: 8,
|
|
|
|
|
right: 8,
|
|
|
|
|
top: 8,
|
|
|
|
|
),
|
|
|
|
|
itemCount: state.hasReachedMax
|
|
|
|
|
? state.operations.length
|
|
|
|
|
: state.operations.length + 1,
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
if (index >= state.operations.length) {
|
|
|
|
|
return const Center(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: EdgeInsets.all(16.0),
|
|
|
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final operation = state.operations[index];
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
|
|
|
|
child: _buildResponsiveCard(operation),
|
2026-06-03 12:08:59 +02:00
|
|
|
);
|
2026-04-16 11:50:29 +02:00
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
2026-06-03 19:16:15 +02:00
|
|
|
|
2026-06-03 12:08:59 +02:00
|
|
|
floatingActionButton: _isSelectionMode
|
2026-06-03 19:16:15 +02:00
|
|
|
? null
|
2026-06-03 12:08:59 +02:00
|
|
|
: FloatingActionButton(
|
2026-06-03 19:16:15 +02:00
|
|
|
onPressed: () async {
|
|
|
|
|
StaffMemberModel? createdBy = await getStaffMember(context);
|
|
|
|
|
if (createdBy == null || !context.mounted) return;
|
|
|
|
|
context.pushNamed(
|
|
|
|
|
Routes.operationForm,
|
|
|
|
|
pathParameters: {'id': 'new'},
|
|
|
|
|
extra: (createdBy: createdBy, operation: null),
|
|
|
|
|
);
|
2026-06-03 12:08:59 +02:00
|
|
|
},
|
|
|
|
|
child: const Icon(Icons.add),
|
|
|
|
|
),
|
2026-04-16 11:50:29 +02:00
|
|
|
);
|
|
|
|
|
}
|
2026-06-03 19:16:15 +02:00
|
|
|
|
|
|
|
|
// --- COSTRUZIONE DELLA COMPONENTISTICA DETTAGLIATA ---
|
|
|
|
|
|
|
|
|
|
Widget _buildResponsiveCard(OperationModel operation) {
|
|
|
|
|
final isSelected = _selectedOperationIds.contains(operation.id);
|
|
|
|
|
return _RichOperationCard(
|
|
|
|
|
operation: operation,
|
|
|
|
|
isSelected: isSelected,
|
|
|
|
|
isSelectionMode: _isSelectionMode,
|
|
|
|
|
onTap: () {
|
|
|
|
|
if (_isSelectionMode) {
|
|
|
|
|
_toggleSelection(operation.id!);
|
|
|
|
|
} else {
|
|
|
|
|
context.pushNamed(
|
|
|
|
|
Routes.operationForm,
|
|
|
|
|
extra: (createdBy: null, operation: operation),
|
|
|
|
|
pathParameters: {'id': operation.id!},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onLongPress: () => _toggleSelection(operation.id!),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 🥷 LA BARRA DI PAGINAZIONE DESKTOP (Stile Gmail / Typesense)
|
|
|
|
|
Widget _buildDesktopPaginationFooter(OperationListState state) {
|
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
|
final cubit = context.read<OperationListCubit>();
|
|
|
|
|
|
|
|
|
|
// Calcolo intervallo visualizzato (es. 1-25 di 140)
|
|
|
|
|
final fromItem = ((state.currentPage - 1) * state.itemsPerPage) + 1;
|
|
|
|
|
final toItem =
|
|
|
|
|
DateUtils.isSameDay(DateTime.now(), DateTime.now()) // segnaposto logico
|
|
|
|
|
? (fromItem + state.operations.length - 1)
|
|
|
|
|
: fromItem;
|
|
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
|
height: 56,
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 24),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: theme.colorScheme.surface,
|
|
|
|
|
border: Border(top: BorderSide(color: theme.dividerColor, width: 0.5)),
|
|
|
|
|
),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
// Info totali a sinistra
|
|
|
|
|
Text(
|
|
|
|
|
"$fromItem-$toItem di ${state.totalItems} pratiche totali",
|
|
|
|
|
style: theme.textTheme.bodyMedium?.copyWith(
|
|
|
|
|
color: Colors.grey[700],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
// Controlli di navigazione a destra
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
// Prima Pagina
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: const Icon(Icons.first_page),
|
|
|
|
|
onPressed: state.currentPage > 1
|
|
|
|
|
? () => cubit.loadSpecificPageDesktop(1)
|
|
|
|
|
: null,
|
|
|
|
|
),
|
|
|
|
|
// Pagina Precedente
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: const Icon(Icons.chevron_left),
|
|
|
|
|
onPressed: state.currentPage > 1
|
|
|
|
|
? () => cubit.loadSpecificPageDesktop(state.currentPage - 1)
|
|
|
|
|
: null,
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
// Indicatore numerico centrale impacchettato
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
|
|
|
child: Text(
|
|
|
|
|
"Pagina ${state.currentPage} di ${state.totalPages}",
|
|
|
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
// Pagina Successiva
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: const Icon(Icons.chevron_right),
|
|
|
|
|
onPressed: state.currentPage < state.totalPages
|
|
|
|
|
? () => cubit.loadSpecificPageDesktop(state.currentPage + 1)
|
|
|
|
|
: null,
|
|
|
|
|
),
|
|
|
|
|
// Ultima Pagina
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: const Icon(Icons.last_page),
|
|
|
|
|
onPressed: state.currentPage < state.totalPages
|
|
|
|
|
? () => cubit.loadSpecificPageDesktop(state.totalPages)
|
|
|
|
|
: null,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-06-03 12:08:59 +02:00
|
|
|
}
|
|
|
|
|
|
2026-06-03 19:16:15 +02:00
|
|
|
// =========================================================================
|
|
|
|
|
// 🥷 3. LA CARD RICCA, REATTIVA E DEFINITIVA (Quella revisionata insieme)
|
|
|
|
|
// =========================================================================
|
2026-06-03 12:08:59 +02:00
|
|
|
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,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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:
|
2026-06-03 19:16:15 +02:00
|
|
|
return Colors.grey.shade800;
|
2026-06-03 12:08:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2026-04-16 11:50:29 +02:00
|
|
|
|
|
|
|
|
return Card(
|
2026-06-03 19:16:15 +02:00
|
|
|
margin: EdgeInsets.zero, // Gestito dai margini dei padri (griglia/lista)
|
2026-06-03 12:08:59 +02:00
|
|
|
elevation: isSelected ? 4 : 1,
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
side: BorderSide(
|
|
|
|
|
color: isSelected ? theme.colorScheme.primary : Colors.transparent,
|
|
|
|
|
width: 2,
|
2026-04-16 11:50:29 +02:00
|
|
|
),
|
2026-06-03 12:08:59 +02:00
|
|
|
),
|
|
|
|
|
child: InkWell(
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
onTap: onTap,
|
|
|
|
|
onLongPress: onLongPress,
|
|
|
|
|
child: ClipRRect(
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
child: Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: isSelected
|
2026-06-03 19:16:15 +02:00
|
|
|
? theme.colorScheme.primaryContainer.withValues(alpha: 0.15)
|
2026-06-03 12:08:59 +02:00
|
|
|
: null,
|
2026-06-03 19:16:15 +02:00
|
|
|
// 🥷 COERENZA 100%: Banda laterale legata allo status per eliminare i malintesi cromatici
|
2026-06-03 12:08:59 +02:00
|
|
|
border: Border(left: BorderSide(color: statusColor, width: 6)),
|
2026-04-16 11:50:29 +02:00
|
|
|
),
|
2026-06-03 12:08:59 +02:00
|
|
|
padding: const EdgeInsets.all(12),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2026-04-16 11:50:29 +02:00
|
|
|
children: [
|
2026-06-03 19:16:15 +02:00
|
|
|
// --- LINEA HEADER ---
|
2026-06-03 12:08:59 +02:00
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
if (isSelectionMode)
|
2026-06-03 19:16:15 +02:00
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
|
|
|
|
child: SizedBox(
|
|
|
|
|
height: 18,
|
|
|
|
|
width: 18,
|
|
|
|
|
child: Checkbox(
|
|
|
|
|
value: isSelected,
|
|
|
|
|
onChanged: (_) => onTap(),
|
|
|
|
|
),
|
2026-06-03 12:08:59 +02:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Text(
|
2026-06-03 19:16:15 +02:00
|
|
|
(operation.reference.isEmpty)
|
|
|
|
|
? 'Senza Riferimento'
|
2026-06-03 13:20:22 +02:00
|
|
|
: operation.reference,
|
2026-06-03 12:08:59 +02:00
|
|
|
style: theme.textTheme.labelSmall?.copyWith(
|
|
|
|
|
color: Colors.grey[600],
|
|
|
|
|
),
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Text(
|
2026-06-03 19:16:15 +02:00
|
|
|
operation.createdAt != null
|
|
|
|
|
? "${operation.createdAt!.day.toString().padLeft(2, '0')}/${operation.createdAt!.month.toString().padLeft(2, '0')}/${operation.createdAt!.year}"
|
|
|
|
|
: '',
|
2026-06-03 12:08:59 +02:00
|
|
|
style: theme.textTheme.labelSmall?.copyWith(
|
|
|
|
|
color: Colors.grey[600],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
|
2026-06-03 19:16:15 +02:00
|
|
|
// --- LINEA CENTRALE: CLIENTE + INSERTO OPERATIVO ---
|
2026-06-03 12:08:59 +02:00
|
|
|
Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Text(
|
|
|
|
|
operation.customer?.name ?? "Cliente sconosciuto",
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontWeight: FontWeight.bold,
|
2026-06-03 19:16:15 +02:00
|
|
|
fontSize: 15,
|
2026-06-03 12:08:59 +02:00
|
|
|
),
|
|
|
|
|
maxLines: 2,
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 8),
|
2026-06-03 19:16:15 +02:00
|
|
|
|
|
|
|
|
// 🥷 IL RE DEL SERVICE: Il tipo operazione svetta con box e contrasto ad hoc
|
2026-06-03 12:08:59 +02:00
|
|
|
Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(
|
2026-06-03 19:16:15 +02:00
|
|
|
horizontal: 8,
|
|
|
|
|
vertical: 4,
|
2026-06-03 12:08:59 +02:00
|
|
|
),
|
|
|
|
|
decoration: BoxDecoration(
|
2026-06-03 19:16:15 +02:00
|
|
|
color: typeColor.withValues(alpha: 0.12),
|
|
|
|
|
borderRadius: BorderRadius.circular(6),
|
2026-06-03 12:08:59 +02:00
|
|
|
border: Border.all(
|
2026-06-03 19:16:15 +02:00
|
|
|
color: typeColor.withValues(alpha: 0.25),
|
2026-06-03 12:08:59 +02:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
if (_getIconForType(
|
|
|
|
|
operation.type,
|
|
|
|
|
operation.subType,
|
|
|
|
|
) !=
|
|
|
|
|
null) ...[
|
|
|
|
|
Icon(
|
|
|
|
|
_getIconForType(
|
|
|
|
|
operation.type,
|
|
|
|
|
operation.subType,
|
|
|
|
|
),
|
2026-06-03 19:16:15 +02:00
|
|
|
size: 13,
|
2026-06-03 12:08:59 +02:00
|
|
|
color: typeColor,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 4),
|
|
|
|
|
],
|
|
|
|
|
Text(
|
2026-06-03 19:16:15 +02:00
|
|
|
(operation.subType != null &&
|
|
|
|
|
operation.subType!.isNotEmpty)
|
2026-06-03 12:08:59 +02:00
|
|
|
? operation.subType!
|
|
|
|
|
: operation.type,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: typeColor,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
2026-06-03 19:16:15 +02:00
|
|
|
fontSize: 11,
|
2026-06-03 12:08:59 +02:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2026-06-03 19:16:15 +02:00
|
|
|
const SizedBox(height: 10),
|
2026-06-03 12:08:59 +02:00
|
|
|
|
2026-06-03 19:16:15 +02:00
|
|
|
// --- LINEA DEI TAG TECNICI ---
|
2026-06-03 12:08:59 +02:00
|
|
|
Wrap(
|
|
|
|
|
spacing: 6,
|
2026-06-03 19:16:15 +02:00
|
|
|
runSpacing: 4,
|
2026-06-03 12:08:59 +02:00
|
|
|
children: [
|
2026-06-03 19:16:15 +02:00
|
|
|
// Tag Target Espanso (Privato / Business)
|
2026-06-03 12:08:59 +02:00
|
|
|
_MiniChip(
|
|
|
|
|
label: operation.isBusiness ? 'Business' : 'Privato',
|
|
|
|
|
icon: operation.isBusiness
|
|
|
|
|
? Icons.business
|
|
|
|
|
: Icons.person,
|
|
|
|
|
color: operation.isBusiness ? Colors.indigo : Colors.teal,
|
|
|
|
|
),
|
|
|
|
|
|
2026-06-03 19:16:15 +02:00
|
|
|
// Tag Gestore (Agganciato dinamicamente al displayColor generato dall'esadecimale del DB!)
|
2026-06-03 12:08:59 +02:00
|
|
|
if (operation.providerId != null)
|
|
|
|
|
_MiniChip(
|
2026-06-03 19:16:15 +02:00
|
|
|
label: operation.provider?.name ?? 'Gestore',
|
|
|
|
|
color:
|
|
|
|
|
operation.provider?.displayColor ?? Colors.blueGrey,
|
2026-06-03 12:08:59 +02:00
|
|
|
),
|
|
|
|
|
|
2026-06-03 19:16:15 +02:00
|
|
|
// Specifiche addizionali del Finanziamento
|
2026-06-03 12:08:59 +02:00
|
|
|
if (operation.type == 'Fin' && operation.modelId != null)
|
|
|
|
|
_MiniChip(
|
2026-06-03 19:16:15 +02:00
|
|
|
label: operation.modelDisplayName ?? 'Prodotto',
|
2026-06-03 12:08:59 +02:00
|
|
|
icon: Icons.devices,
|
|
|
|
|
color: Colors.deepPurple,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
const Spacer(),
|
|
|
|
|
|
2026-06-03 19:16:15 +02:00
|
|
|
// --- FOOTER CARD: AGENTE + CHIP STATO ---
|
2026-06-03 12:08:59 +02:00
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
const Icon(
|
|
|
|
|
Icons.support_agent,
|
|
|
|
|
size: 14,
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 4),
|
|
|
|
|
Text(
|
2026-06-03 19:16:15 +02:00
|
|
|
operation.staffDisplayName ?? 'Assegnato',
|
2026-06-03 12:08:59 +02:00
|
|
|
style: theme.textTheme.labelSmall?.copyWith(
|
|
|
|
|
color: Colors.grey[700],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2026-06-03 19:16:15 +02:00
|
|
|
Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
|
horizontal: 8,
|
|
|
|
|
vertical: 4,
|
|
|
|
|
),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: statusColor,
|
|
|
|
|
borderRadius: BorderRadius.circular(6),
|
|
|
|
|
),
|
|
|
|
|
child: Text(
|
|
|
|
|
operation.status.displayName,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 10,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2026-06-03 12:08:59 +02:00
|
|
|
],
|
|
|
|
|
),
|
2026-04-16 11:50:29 +02:00
|
|
|
],
|
|
|
|
|
),
|
2026-06-03 12:08:59 +02:00
|
|
|
),
|
2026-04-20 16:52:20 +02:00
|
|
|
),
|
2026-04-16 11:50:29 +02:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-03 12:08:59 +02:00
|
|
|
IconData? _getIconForType(String type, String? subtype) {
|
|
|
|
|
if (type == 'Energy') {
|
|
|
|
|
if (subtype?.toLowerCase() == 'luce') return Icons.bolt;
|
|
|
|
|
if (subtype?.toLowerCase() == 'gas') return Icons.local_fire_department;
|
2026-05-04 15:36:42 +02:00
|
|
|
}
|
2026-06-03 12:08:59 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-03 19:16:15 +02:00
|
|
|
// Micro Widget di supporto per i tag interni
|
2026-06-03 12:08:59 +02:00
|
|
|
class _MiniChip extends StatelessWidget {
|
|
|
|
|
final String label;
|
|
|
|
|
final IconData? icon;
|
|
|
|
|
final Color color;
|
2026-05-04 15:36:42 +02:00
|
|
|
|
2026-06-03 12:08:59 +02:00
|
|
|
const _MiniChip({required this.label, this.icon, required this.color});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Container(
|
2026-06-03 19:16:15 +02:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 3),
|
2026-06-03 12:08:59 +02:00
|
|
|
decoration: BoxDecoration(
|
2026-06-03 19:16:15 +02:00
|
|
|
color: color.withValues(alpha: 0.08),
|
|
|
|
|
border: Border.all(color: color.withValues(alpha: 0.25)),
|
|
|
|
|
borderRadius: BorderRadius.circular(4),
|
2026-06-03 12:08:59 +02:00
|
|
|
),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
if (icon != null) ...[
|
2026-06-03 19:16:15 +02:00
|
|
|
Icon(icon, size: 11, color: color),
|
2026-06-03 12:08:59 +02:00
|
|
|
const SizedBox(width: 4),
|
|
|
|
|
],
|
|
|
|
|
Text(
|
|
|
|
|
label,
|
|
|
|
|
style: TextStyle(
|
2026-06-03 19:16:15 +02:00
|
|
|
fontSize: 10,
|
2026-06-03 12:08:59 +02:00
|
|
|
color: color,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
2026-05-04 15:36:42 +02:00
|
|
|
}
|
2026-04-16 11:50:29 +02:00
|
|
|
}
|