Clean-Arch-Schichten für Cars: - lib/domain/entity/car.dart: UUID-id, accountId (Personalnummer), plate, active. Pendant zum Backend-Schema. - lib/domain/repository/cars_repository.dart: Port — listMine, create, update. Keine teamId/personalnummer-Parameter, der Account fließt serverseitig aus dem JWT. - lib/data/mapper/car_mapper.dart: API-DTO (built_value) → Domain. - lib/data/repository/cars_repository_impl.dart: konkrete Impl via generierter CarsApi (dio), mit DioException → CarsRepositoryException- Übersetzung. Feature-Cars-Refactoring: - CarsBloc nimmt jetzt die Domain-Repository-Schnittstelle. Events: CarLoad/CarAdd/CarEdit/CarDeactivate (statt CarDelete). Keine teamId-Parameter mehr. Kein authBloc-Bezug, Session-Expiry läuft über den globalen Provider-Stream. - CarsState sealed mit CarsInitial/Loading/LoadingFailed/Loaded. - Pages: car_management_page, car_management, car_card, car_fail_page, car_selection_page komplett auf die neue Entity und Event-Signaturen. - Alte lib/feature/cars/service/cars_service.dart und lib/feature/cars/repository/cars_repository.dart gelöscht. CarSelectBloc + Storage: - CarSelection.selectedCarId von int? auf String? umgestellt. - CarSelectionRepository persistiert die UUID jetzt als String; defensive Migration für noch vorhandene int-Werte (alte Pre-Migration-Installations) verwirft den Wert leise und erzwingt Neuauswahl. Konsequenz-Cleanup im Tour-Code (Phase-D-Vorbereitung): - Delivery.carId String? statt int?. - Tour.hasUndeliveredLoadedArticles / getFinishedDeliveries auf String carId. - _selectedCarId / int? carId / int selectedCarId in DeliveryOverview, LoadingCustomerPage/OverviewPage, Home, DeliverySelection/SortPage, DeliveryInfo/List, CustomSortDialog, SortableDeliveryList auf String umgestellt. - TourRepository ersetzt int.parse(carId)/int.tryParse-Zuweisungen direkt durch String. - lib/model/car.dart wird zum Re-Export der neuen Domain-Entity, damit Legacy-Imports während Phase-D-Übergang weiter compilieren. DI: - app.dart: CarsBloc bekommt CarsRepositoryImpl(locator<HolzleitnerApi>()) statt der alten CarsRepository(service: CarService()). Build (flutter build apk --debug) durch, flutter analyze ohne errors.
95 lines
2.8 KiB
Dart
95 lines
2.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:hl_lieferservice/domain/entity/car.dart';
|
|
import 'package:hl_lieferservice/feature/cars/presentation/car_card.dart';
|
|
import 'package:hl_lieferservice/feature/cars/presentation/car_dialog.dart';
|
|
|
|
class CarManagementOverview extends StatefulWidget {
|
|
final List<Car> cars;
|
|
/// UUID des aktuell für heute ausgewählten Fahrzeugs (oder `null`).
|
|
final String? selectedCarId;
|
|
final Function(String plate) onAdd;
|
|
final Function(String id) onDelete;
|
|
final Function(String id, String plate) onEdit;
|
|
final Future<void> Function() onRefresh;
|
|
|
|
const CarManagementOverview({
|
|
super.key,
|
|
required this.cars,
|
|
required this.onDelete,
|
|
required this.onEdit,
|
|
required this.onAdd,
|
|
required this.onRefresh,
|
|
this.selectedCarId,
|
|
});
|
|
|
|
@override
|
|
State<StatefulWidget> createState() => _CarManagementOverviewState();
|
|
}
|
|
|
|
class _CarManagementOverviewState extends State<CarManagementOverview> {
|
|
void _addCar() async {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) {
|
|
return CarDialog(onAction: widget.onAdd);
|
|
},
|
|
);
|
|
}
|
|
|
|
void _removeCar(Car car) {
|
|
widget.onDelete(car.id);
|
|
}
|
|
|
|
void _editCar(Car car, String newName) {
|
|
widget.onEdit(car.id, newName);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text("Fahrzeuge"),
|
|
backgroundColor: Theme.of(context).primaryColor,
|
|
foregroundColor: Theme.of(context).colorScheme.onSecondary,
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: _addCar,
|
|
backgroundColor: Theme.of(context).primaryColor,
|
|
child: Icon(
|
|
Icons.add,
|
|
color: Theme.of(context).colorScheme.onSecondary,
|
|
),
|
|
),
|
|
body: RefreshIndicator(
|
|
onRefresh: widget.onRefresh,
|
|
child: widget.cars.isEmpty
|
|
? ListView(
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
padding: const EdgeInsets.all(10),
|
|
children: const [
|
|
SizedBox(
|
|
height: 200,
|
|
child: Center(child: Text("keine Fahrzeuge vorhanden")),
|
|
),
|
|
],
|
|
)
|
|
: ListView.builder(
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
padding: const EdgeInsets.all(10),
|
|
itemCount: widget.cars.length,
|
|
itemBuilder: (context, index) {
|
|
final car = widget.cars[index];
|
|
return CarCard(
|
|
car: car,
|
|
isSelected: widget.selectedCarId == car.id,
|
|
onEdit: _editCar,
|
|
onDelete: _removeCar,
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|