fix lista ticket
Build and Release FLUX (Multi-Platform) / build-web (push) Successful in 2m7s
Build and Release FLUX (Multi-Platform) / build-linux (push) Successful in 1m28s
Build and Release FLUX (Multi-Platform) / build-windows (push) Successful in 9m33s
Build and Release FLUX (Multi-Platform) / build-macos (push) Failing after 15m1s
Build and Release FLUX (Multi-Platform) / build-web (push) Successful in 2m7s
Build and Release FLUX (Multi-Platform) / build-linux (push) Successful in 1m28s
Build and Release FLUX (Multi-Platform) / build-windows (push) Successful in 9m33s
Build and Release FLUX (Multi-Platform) / build-macos (push) Failing after 15m1s
This commit is contained in:
1 parent
4e3732597b
commit
606a1fc3a9
6 files changed
+302
-82
No files matched your search
@@ -84,6 +84,8 @@ class TicketListCubit extends Cubit<TicketListState> {
|
||||
bool clearSearch = false,
|
||||
bool clearDate = false,
|
||||
bool clearStatus = false,
|
||||
bool clearTicketType = false,
|
||||
bool clearStaff = false,
|
||||
}) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
@@ -95,11 +97,19 @@ class TicketListCubit extends Cubit<TicketListState> {
|
||||
clearSearch: clearSearch,
|
||||
clearDate: clearDate,
|
||||
clearStatus: clearStatus,
|
||||
clearTicketType: clearTicketType,
|
||||
clearStaff: clearStaff,
|
||||
),
|
||||
);
|
||||
loadTickets(refresh: true); // Applica i filtri e ricarica
|
||||
}
|
||||
|
||||
/// Azzera tutti i filtri e ricarica la lista completa
|
||||
void resetFilters() {
|
||||
emit(state.resetFilters());
|
||||
loadTickets(refresh: true);
|
||||
}
|
||||
|
||||
void toggleTicketSelection(TicketModel ticket) {
|
||||
final currentSelection = Set<TicketModel>.from(state.selectedTickets);
|
||||
if (currentSelection.contains(ticket)) {
|
||||
|
||||
@@ -29,6 +29,13 @@ class TicketListState extends Equatable {
|
||||
this.staffIdFilter,
|
||||
});
|
||||
|
||||
bool get hasActiveFilters =>
|
||||
(searchTerm != null && searchTerm!.trim().isNotEmpty) ||
|
||||
dateRange != null ||
|
||||
statusFilter != null ||
|
||||
ticketTypeFilter != null ||
|
||||
(staffIdFilter != null && staffIdFilter!.trim().isNotEmpty);
|
||||
|
||||
TicketListState copyWith({
|
||||
List<TicketModel>? tickets,
|
||||
bool? isLoading,
|
||||
@@ -43,6 +50,8 @@ class TicketListState extends Equatable {
|
||||
bool clearSearch = false,
|
||||
bool clearDate = false,
|
||||
bool clearStatus = false,
|
||||
bool clearTicketType = false,
|
||||
bool clearStaff = false,
|
||||
}) {
|
||||
return TicketListState(
|
||||
tickets: tickets ?? this.tickets,
|
||||
@@ -52,12 +61,28 @@ class TicketListState extends Equatable {
|
||||
searchTerm: clearSearch ? null : (searchTerm ?? this.searchTerm),
|
||||
dateRange: clearDate ? null : (dateRange ?? this.dateRange),
|
||||
statusFilter: clearStatus ? null : (statusFilter ?? this.statusFilter),
|
||||
ticketTypeFilter: ticketTypeFilter ?? this.ticketTypeFilter,
|
||||
staffIdFilter: staffIdFilter ?? this.staffIdFilter,
|
||||
ticketTypeFilter:
|
||||
clearTicketType ? null : (ticketTypeFilter ?? this.ticketTypeFilter),
|
||||
staffIdFilter: clearStaff ? null : (staffIdFilter ?? this.staffIdFilter),
|
||||
selectedTickets: selectedTickets ?? this.selectedTickets,
|
||||
);
|
||||
}
|
||||
|
||||
TicketListState resetFilters() {
|
||||
return TicketListState(
|
||||
tickets: tickets,
|
||||
isLoading: isLoading,
|
||||
hasReachedMax: hasReachedMax,
|
||||
errorMessage: errorMessage,
|
||||
selectedTickets: selectedTickets,
|
||||
searchTerm: null,
|
||||
dateRange: null,
|
||||
statusFilter: null,
|
||||
ticketTypeFilter: null,
|
||||
staffIdFilter: null,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
tickets,
|
||||
|
||||
@@ -66,7 +66,7 @@ class TicketRepository {
|
||||
}
|
||||
|
||||
if (statusFilter != null) {
|
||||
query = query.eq('status', statusFilter.value);
|
||||
query = query.eq('ticket_status', statusFilter.value);
|
||||
}
|
||||
|
||||
if (ticketTypeFilter != null) {
|
||||
@@ -159,7 +159,7 @@ class TicketRepository {
|
||||
}
|
||||
|
||||
if (ticketStatusFilter != null) {
|
||||
query = query.eq('status', ticketStatusFilter.value);
|
||||
query = query.eq('ticket_status', ticketStatusFilter.value);
|
||||
}
|
||||
|
||||
if (ticketTypeFilter != null) {
|
||||
|
||||
@@ -45,6 +45,12 @@ class _TicketListScreenState extends State<TicketListScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
void _resetAllFilters() {
|
||||
_debounce?.cancel();
|
||||
_searchController.clear();
|
||||
context.read<TicketListCubit>().resetFilters();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_debounce?.cancel();
|
||||
@@ -59,6 +65,16 @@ class _TicketListScreenState extends State<TicketListScreen> {
|
||||
appBar: AppBar(
|
||||
title: const Text('Assistenza & Riparazioni'),
|
||||
actions: [
|
||||
BlocBuilder<TicketListCubit, TicketListState>(
|
||||
builder: (context, state) {
|
||||
if (!state.hasActiveFilters) return const SizedBox.shrink();
|
||||
return IconButton(
|
||||
tooltip: 'Azzera filtri',
|
||||
icon: const Icon(Icons.filter_alt_off),
|
||||
onPressed: _resetAllFilters,
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () =>
|
||||
context.read<TicketListCubit>().loadTickets(refresh: true),
|
||||
@@ -73,87 +89,189 @@ class _TicketListScreenState extends State<TicketListScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
// 1. BARRA DI RICERCA
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Cerca per cliente, richiesta o riferimento...',
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
suffixIcon: IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
onPressed: () {
|
||||
_debounce?.cancel();
|
||||
_searchController.clear();
|
||||
context.read<TicketListCubit>().updateFilters(
|
||||
clearSearch: true,
|
||||
);
|
||||
},
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
body: BlocListener<TicketListCubit, TicketListState>(
|
||||
listenWhen: (previous, current) =>
|
||||
previous.searchTerm != current.searchTerm &&
|
||||
(current.searchTerm == null || current.searchTerm!.isEmpty),
|
||||
listener: (context, state) {
|
||||
if (_searchController.text.isNotEmpty) {
|
||||
_searchController.clear();
|
||||
}
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
// 1. BARRA DI RICERCA
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Cerca per cliente, richiesta o riferimento...',
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
suffixIcon: IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
onPressed: () {
|
||||
_debounce?.cancel();
|
||||
_searchController.clear();
|
||||
context.read<TicketListCubit>().updateFilters(
|
||||
clearSearch: true,
|
||||
);
|
||||
},
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
onChanged: _onSearchChanged,
|
||||
onSubmitted: (value) {
|
||||
_debounce?.cancel();
|
||||
context.read<TicketListCubit>().updateFilters(
|
||||
searchTerm: value,
|
||||
);
|
||||
},
|
||||
),
|
||||
onChanged: _onSearchChanged,
|
||||
onSubmitted: (value) {
|
||||
_debounce?.cancel();
|
||||
context.read<TicketListCubit>().updateFilters(
|
||||
searchTerm: value,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
// 2. FILTRI RAPIDI PER STATO (CHIPS)
|
||||
BlocBuilder<TicketListCubit, TicketListState>(
|
||||
buildWhen: (previous, current) =>
|
||||
previous.statusFilter != current.statusFilter,
|
||||
builder: (context, state) {
|
||||
return SizedBox(
|
||||
height: 50,
|
||||
child: ListView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||
children: [
|
||||
_buildStatusChip(context, state, null, 'Tutti'),
|
||||
...TicketStatus.values.map(
|
||||
(status) => _buildStatusChip(
|
||||
context,
|
||||
state,
|
||||
status,
|
||||
status.displayValue,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const Divider(),
|
||||
|
||||
// 3. LA LISTA DEI TICKET
|
||||
Expanded(
|
||||
child: BlocBuilder<TicketListCubit, TicketListState>(
|
||||
// 2. FILTRI RAPIDI PER STATO (CHIPS)
|
||||
BlocBuilder<TicketListCubit, TicketListState>(
|
||||
buildWhen: (previous, current) =>
|
||||
previous.statusFilter != current.statusFilter ||
|
||||
previous.hasActiveFilters != current.hasActiveFilters,
|
||||
builder: (context, state) {
|
||||
if (state.isLoading && state.tickets.isEmpty) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (state.tickets.isEmpty) {
|
||||
return const Center(child: Text('Nessun ticket trovato.'));
|
||||
}
|
||||
|
||||
return TicketList(
|
||||
state: state,
|
||||
scrollController: _scrollController,
|
||||
return SizedBox(
|
||||
height: 50,
|
||||
child: ListView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||
children: [
|
||||
if (state.hasActiveFilters)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: ActionChip(
|
||||
avatar: const Icon(
|
||||
Icons.filter_alt_off,
|
||||
size: 16,
|
||||
color: Colors.redAccent,
|
||||
),
|
||||
label: const Text(
|
||||
'Azzera filtri',
|
||||
style: TextStyle(
|
||||
color: Colors.redAccent,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
backgroundColor:
|
||||
Colors.redAccent.withValues(alpha: 0.1),
|
||||
side: BorderSide(
|
||||
color: Colors.redAccent.withValues(alpha: 0.3),
|
||||
),
|
||||
onPressed: _resetAllFilters,
|
||||
),
|
||||
),
|
||||
_buildStatusChip(context, state, null, 'Tutti'),
|
||||
...TicketStatus.values.map(
|
||||
(status) => _buildStatusChip(
|
||||
context,
|
||||
state,
|
||||
status,
|
||||
status.displayValue,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
const Divider(),
|
||||
|
||||
// 3. LA LISTA DEI TICKET
|
||||
Expanded(
|
||||
child: BlocBuilder<TicketListCubit, TicketListState>(
|
||||
builder: (context, state) {
|
||||
if (state.isLoading && state.tickets.isEmpty) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (state.errorMessage.isNotEmpty && state.tickets.isEmpty) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.error_outline,
|
||||
size: 48,
|
||||
color: Colors.red,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
state.errorMessage,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(color: Colors.red),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () => context
|
||||
.read<TicketListCubit>()
|
||||
.loadTickets(refresh: true),
|
||||
icon: const Icon(Icons.refresh),
|
||||
label: const Text('Riprova'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (state.tickets.isEmpty) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
state.hasActiveFilters
|
||||
? Icons.filter_list_off
|
||||
: Icons.inbox_outlined,
|
||||
size: 48,
|
||||
color: Colors.grey,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
state.hasActiveFilters
|
||||
? 'Nessun ticket trovato con i filtri selezionati.'
|
||||
: 'Nessun ticket trovato.',
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
if (state.hasActiveFilters) ...[
|
||||
const SizedBox(height: 16),
|
||||
OutlinedButton.icon(
|
||||
onPressed: _resetAllFilters,
|
||||
icon: const Icon(Icons.filter_alt_off),
|
||||
label: const Text('Azzera filtri'),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return TicketList(
|
||||
state: state,
|
||||
scrollController: _scrollController,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
icon: const Icon(Icons.add),
|
||||
@@ -184,16 +302,29 @@ class _TicketListScreenState extends State<TicketListScreen> {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: ChoiceChip(
|
||||
avatar: status != null
|
||||
? Icon(
|
||||
status.icon,
|
||||
size: 16,
|
||||
color: isSelected ? status.color : null,
|
||||
)
|
||||
: const Icon(Icons.apps, size: 16),
|
||||
label: Text(label),
|
||||
selected: isSelected,
|
||||
selectedColor:
|
||||
status?.color.withValues(alpha: 0.2) ??
|
||||
Colors.blue.withValues(alpha: 0.2),
|
||||
onSelected: (selected) {
|
||||
context.read<TicketListCubit>().updateFilters(
|
||||
statusFilter: selected ? status : null,
|
||||
clearStatus: !selected && status != null,
|
||||
);
|
||||
if (status == null) {
|
||||
if (!isSelected) {
|
||||
context.read<TicketListCubit>().updateFilters(clearStatus: true);
|
||||
}
|
||||
} else {
|
||||
context.read<TicketListCubit>().updateFilters(
|
||||
statusFilter: selected ? status : null,
|
||||
clearStatus: !selected,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user