fix phone dashboard
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import '../../../core/models/vehicle.dart';
|
||||
import '../providers/dashboard_providers.dart';
|
||||
import '../../../widgets/vehicle_card.dart';
|
||||
import '../../../widgets/loading_list.dart';
|
||||
@@ -26,12 +28,45 @@ class _VehiclesScreenState extends ConsumerState<VehiclesScreen> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Map<String, dynamic> get _params => {
|
||||
'page': 1,
|
||||
'pageSize': 50,
|
||||
if (_statusFilter != null) 'status': _statusFilter,
|
||||
if (_search.isNotEmpty) 'search': _search,
|
||||
};
|
||||
VehicleQuery get _params => (
|
||||
page: 1,
|
||||
pageSize: 100,
|
||||
status: null,
|
||||
);
|
||||
|
||||
List<Vehicle> _filterVehicles(List<Vehicle> vehicles) {
|
||||
final query = _search.trim().toLowerCase();
|
||||
final status = _statusFilter;
|
||||
|
||||
return vehicles.where((vehicle) {
|
||||
if (status != null && vehicle.status != status) {
|
||||
return false;
|
||||
}
|
||||
if (query.isEmpty) {
|
||||
return true;
|
||||
}
|
||||
final haystack = [
|
||||
vehicle.displayName,
|
||||
vehicle.licensePlate,
|
||||
vehicle.status,
|
||||
vehicle.category,
|
||||
].join(' ').toLowerCase();
|
||||
return haystack.contains(query);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
String _errorMessage(Object error) {
|
||||
if (error is DioException) {
|
||||
final data = error.response?.data;
|
||||
if (data is Map<String, dynamic>) {
|
||||
final message = data['message'];
|
||||
if (message is String && message.isNotEmpty) {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 'Failed to load vehicles';
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -48,7 +83,7 @@ class _VehiclesScreenState extends ConsumerState<VehiclesScreen> {
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
appBar: AppBar(
|
||||
title: const Text('Vehicles'),
|
||||
title: const Text('Fleet'),
|
||||
bottom: PreferredSize(
|
||||
preferredSize: const Size.fromHeight(60),
|
||||
child: Padding(
|
||||
@@ -86,34 +121,40 @@ class _VehiclesScreenState extends ConsumerState<VehiclesScreen> {
|
||||
body: vehiclesAsync.when(
|
||||
loading: () => const LoadingList(itemHeight: 240),
|
||||
error: (e, _) => ErrorView(
|
||||
message: 'Failed to load vehicles',
|
||||
message: _errorMessage(e),
|
||||
onRetry: () => ref.invalidate(vehiclesProvider(_params)),
|
||||
),
|
||||
data: (res) => res.data.isEmpty
|
||||
? const Center(
|
||||
data: (res) {
|
||||
final filteredVehicles = _filterVehicles(res.data);
|
||||
|
||||
return filteredVehicles.isEmpty
|
||||
? const Center(
|
||||
child: Text(
|
||||
'No vehicles found',
|
||||
style: TextStyle(color: Color(0xFF9CA3AF)),
|
||||
),
|
||||
)
|
||||
: RefreshIndicator(
|
||||
onRefresh: () async =>
|
||||
ref.invalidate(vehiclesProvider(_params)),
|
||||
child: GridView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 1,
|
||||
mainAxisExtent: 240,
|
||||
mainAxisSpacing: 12,
|
||||
: RefreshIndicator(
|
||||
onRefresh: () async =>
|
||||
ref.invalidate(vehiclesProvider(_params)),
|
||||
child: GridView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
gridDelegate:
|
||||
const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 1,
|
||||
mainAxisExtent: 240,
|
||||
mainAxisSpacing: 12,
|
||||
),
|
||||
itemCount: filteredVehicles.length,
|
||||
itemBuilder: (_, i) => VehicleCard(
|
||||
vehicle: filteredVehicles[i],
|
||||
onTap: () => context.push(
|
||||
'/dashboard/fleet/${filteredVehicles[i].id}',
|
||||
),
|
||||
),
|
||||
),
|
||||
itemCount: res.data.length,
|
||||
itemBuilder: (_, i) => VehicleCard(
|
||||
vehicle: res.data[i],
|
||||
onTap: () =>
|
||||
context.push('/dashboard/vehicles/${res.data[i].id}'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user