fix phone dashboard
This commit is contained in:
@@ -15,6 +15,33 @@ class _ContractsScreenState extends ConsumerState<ContractsScreen> {
|
||||
final _searchCtrl = TextEditingController();
|
||||
String _search = '';
|
||||
|
||||
List<Reservation> _visibleContracts(List<Reservation> reservations) {
|
||||
final query = _search.trim().toLowerCase();
|
||||
|
||||
return reservations.where((reservation) {
|
||||
if (reservation.contractNumber == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (query.isEmpty) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final customer = reservation.customer;
|
||||
final vehicle = reservation.vehicle;
|
||||
final haystack = [
|
||||
customer?.fullName,
|
||||
customer?.email,
|
||||
vehicle?.displayName,
|
||||
vehicle?.licensePlate,
|
||||
reservation.contractNumber,
|
||||
reservation.invoiceNumber,
|
||||
].whereType<String>().join(' ').toLowerCase();
|
||||
|
||||
return haystack.contains(query);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchCtrl.dispose();
|
||||
@@ -23,12 +50,14 @@ class _ContractsScreenState extends ConsumerState<ContractsScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final params = {
|
||||
'page': 1,
|
||||
'pageSize': 100,
|
||||
'status': 'CONFIRMED,ACTIVE,COMPLETED,CLOSED',
|
||||
if (_search.isNotEmpty) 'search': _search,
|
||||
};
|
||||
final ReservationQuery params = (
|
||||
page: 1,
|
||||
pageSize: 100,
|
||||
status: null,
|
||||
source: null,
|
||||
search: null,
|
||||
customerId: null,
|
||||
);
|
||||
|
||||
final asyncData = ref.watch(reservationsProvider(params));
|
||||
|
||||
@@ -69,9 +98,7 @@ class _ContractsScreenState extends ConsumerState<ContractsScreen> {
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (e, _) => Center(child: Text('Error: $e')),
|
||||
data: (response) {
|
||||
final contracts = response.data
|
||||
.where((r) => r.contractNumber != null)
|
||||
.toList();
|
||||
final contracts = _visibleContracts(response.data);
|
||||
|
||||
if (contracts.isEmpty) {
|
||||
return const Center(
|
||||
|
||||
Reference in New Issue
Block a user