add dashboard to phone app
This commit is contained in:
@@ -5,6 +5,8 @@ import '../providers/dashboard_providers.dart';
|
||||
import '../../../widgets/vehicle_card.dart';
|
||||
import '../../../widgets/loading_list.dart';
|
||||
import '../../../widgets/error_view.dart';
|
||||
import 'dashboard_shell.dart';
|
||||
import 'vehicle_form_screen.dart';
|
||||
|
||||
class VehiclesScreen extends ConsumerStatefulWidget {
|
||||
const VehiclesScreen({super.key});
|
||||
@@ -25,17 +27,26 @@ class _VehiclesScreenState extends ConsumerState<VehiclesScreen> {
|
||||
}
|
||||
|
||||
Map<String, dynamic> get _params => {
|
||||
'page': 1,
|
||||
'pageSize': 50,
|
||||
if (_statusFilter != null) 'status': _statusFilter,
|
||||
if (_search.isNotEmpty) 'search': _search,
|
||||
};
|
||||
'page': 1,
|
||||
'pageSize': 50,
|
||||
if (_statusFilter != null) 'status': _statusFilter,
|
||||
if (_search.isNotEmpty) 'search': _search,
|
||||
};
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final vehiclesAsync = ref.watch(vehiclesProvider(_params));
|
||||
|
||||
return Scaffold(
|
||||
return DashboardShell(
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () async {
|
||||
final result = await Navigator.of(context).push<bool>(
|
||||
MaterialPageRoute(builder: (_) => const VehicleFormScreen()),
|
||||
);
|
||||
if (result == true) ref.invalidate(vehiclesProvider(_params));
|
||||
},
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
appBar: AppBar(
|
||||
title: const Text('Vehicles'),
|
||||
bottom: PreferredSize(
|
||||
@@ -57,9 +68,7 @@ class _VehiclesScreenState extends ConsumerState<VehiclesScreen> {
|
||||
PopupMenuButton<String?>(
|
||||
icon: Icon(
|
||||
Icons.filter_list,
|
||||
color: _statusFilter != null
|
||||
? const Color(0xFF1A56DB)
|
||||
: null,
|
||||
color: _statusFilter != null ? const Color(0xFF1A56DB) : null,
|
||||
),
|
||||
onSelected: (v) => setState(() => _statusFilter = v),
|
||||
itemBuilder: (_) => [
|
||||
@@ -67,7 +76,9 @@ class _VehiclesScreenState extends ConsumerState<VehiclesScreen> {
|
||||
const PopupMenuItem(value: 'AVAILABLE', child: Text('Available')),
|
||||
const PopupMenuItem(value: 'RENTED', child: Text('Rented')),
|
||||
const PopupMenuItem(
|
||||
value: 'MAINTENANCE', child: Text('Maintenance')),
|
||||
value: 'MAINTENANCE',
|
||||
child: Text('Maintenance'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -80,15 +91,17 @@ class _VehiclesScreenState extends ConsumerState<VehiclesScreen> {
|
||||
),
|
||||
data: (res) => res.data.isEmpty
|
||||
? const Center(
|
||||
child: Text('No vehicles found',
|
||||
style: TextStyle(color: Color(0xFF9CA3AF))))
|
||||
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(
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 1,
|
||||
mainAxisExtent: 240,
|
||||
mainAxisSpacing: 12,
|
||||
@@ -96,8 +109,8 @@ class _VehiclesScreenState extends ConsumerState<VehiclesScreen> {
|
||||
itemCount: res.data.length,
|
||||
itemBuilder: (_, i) => VehicleCard(
|
||||
vehicle: res.data[i],
|
||||
onTap: () => context
|
||||
.push('/dashboard/vehicles/${res.data[i].id}'),
|
||||
onTap: () =>
|
||||
context.push('/dashboard/vehicles/${res.data[i].id}'),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user