106 lines
3.3 KiB
Dart
106 lines
3.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../models/vehicle.dart';
|
|
import '../services/app_state.dart';
|
|
import 'add_edit_vehicle_screen.dart';
|
|
import 'settings_screen.dart';
|
|
import 'vehicle_detail_screen.dart';
|
|
|
|
class HomeScreen extends StatelessWidget {
|
|
const HomeScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final appState = context.watch<AppState>();
|
|
final vehicles = appState.vehicles;
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('My Vehicles'),
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.settings_outlined),
|
|
tooltip: 'Settings',
|
|
onPressed: () => Navigator.of(context).push(
|
|
MaterialPageRoute(builder: (_) => const SettingsScreen()),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
body: vehicles.isEmpty
|
|
? const _EmptyState()
|
|
: ListView.separated(
|
|
padding: const EdgeInsets.all(12),
|
|
itemCount: vehicles.length,
|
|
separatorBuilder: (_, _) => const SizedBox(height: 8),
|
|
itemBuilder: (context, index) {
|
|
final vehicle = vehicles[index];
|
|
final gallons = appState.totalGallonsForVehicle(vehicle.id);
|
|
return _VehicleCard(vehicle: vehicle, totalGallons: gallons);
|
|
},
|
|
),
|
|
floatingActionButton: FloatingActionButton.extended(
|
|
onPressed: () => Navigator.of(context).push(
|
|
MaterialPageRoute(builder: (_) => const AddEditVehicleScreen()),
|
|
),
|
|
icon: const Icon(Icons.add),
|
|
label: const Text('Add Vehicle'),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _VehicleCard extends StatelessWidget {
|
|
final Vehicle vehicle;
|
|
final double totalGallons;
|
|
|
|
const _VehicleCard({required this.vehicle, required this.totalGallons});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Card(
|
|
clipBehavior: Clip.antiAlias,
|
|
child: ListTile(
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
leading: CircleAvatar(
|
|
child: Text(vehicle.make.isNotEmpty ? vehicle.make[0].toUpperCase() : '?'),
|
|
),
|
|
title: Text('${vehicle.color} ${vehicle.make} ${vehicle.model}'),
|
|
subtitle: Text(
|
|
'Plate: ${vehicle.licensePlate}\n${totalGallons.toStringAsFixed(3)} gallons logged',
|
|
),
|
|
isThreeLine: true,
|
|
trailing: const Icon(Icons.chevron_right),
|
|
onTap: () => Navigator.of(context).push(
|
|
MaterialPageRoute(builder: (_) => VehicleDetailScreen(vehicleId: vehicle.id)),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _EmptyState extends StatelessWidget {
|
|
const _EmptyState();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(32),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(Icons.local_shipping_outlined, size: 64, color: Theme.of(context).colorScheme.outline),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
'No vehicles yet. Add a vehicle to start logging fuel receipts.',
|
|
textAlign: TextAlign.center,
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|