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.
145 lines
6.1 KiB
Dart
145 lines
6.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:hl_lieferservice/bloc/app_bloc.dart';
|
|
import 'package:hl_lieferservice/data/network/keycloak_oidc_token_provider.dart';
|
|
import 'package:hl_lieferservice/feature/authentication/bloc/auth_bloc.dart';
|
|
import 'package:hl_lieferservice/feature/authentication/bloc/auth_event.dart';
|
|
import 'package:hl_lieferservice/feature/authentication/presentation/login_enforcer.dart';
|
|
import 'package:hl_lieferservice/main.dart' show locator;
|
|
import 'package:hl_lieferservice/feature/car_selection/bloc/bloc.dart';
|
|
import 'package:hl_lieferservice/feature/car_selection/presentation/car_selection_enforcer.dart';
|
|
import 'package:hl_lieferservice/feature/car_selection/repository/car_selection_repository.dart';
|
|
import 'package:hl_lieferservice/data/repository/cars_repository_impl.dart';
|
|
import 'package:hl_lieferservice/feature/cars/bloc/cars_bloc.dart';
|
|
import 'package:hl_lieferservice/feature/cars/presentation/car_management_page.dart';
|
|
import 'package:holzleitner_api/holzleitner_api.dart' show HolzleitnerApi;
|
|
import 'package:hl_lieferservice/feature/delivery/bloc/phase_bloc.dart';
|
|
import 'package:hl_lieferservice/feature/delivery/bloc/tour_bloc.dart';
|
|
import 'package:hl_lieferservice/feature/delivery/bloc/tour_state.dart';
|
|
import 'package:hl_lieferservice/feature/delivery/repository/tour_repository.dart';
|
|
import 'package:hl_lieferservice/widget/home/bloc/navigation_bloc.dart';
|
|
import 'package:hl_lieferservice/widget/operations/bloc/operation_bloc.dart';
|
|
import 'package:hl_lieferservice/widget/operations/presentation/operation_view_enforcer.dart';
|
|
|
|
import 'package:hl_lieferservice/bloc/app_states.dart';
|
|
import '../feature/delivery/service/tour_service.dart';
|
|
import 'home/presentation/home.dart';
|
|
|
|
class DeliveryApp extends StatefulWidget {
|
|
const DeliveryApp({super.key});
|
|
|
|
@override
|
|
State<StatefulWidget> createState() => _DeliveryAppState();
|
|
}
|
|
|
|
class _DeliveryAppState extends State<DeliveryApp> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocBuilder<AppBloc, AppState>(
|
|
builder: (context, state) {
|
|
if (state is AppConfigLoaded) {
|
|
return MultiBlocProvider(
|
|
providers: [
|
|
BlocProvider(create: (context) => NavigationBloc()),
|
|
BlocProvider(create: (context) => OperationBloc()),
|
|
BlocProvider(
|
|
create:
|
|
(context) => AuthBloc(
|
|
tokenProvider:
|
|
locator<KeycloakOidcTokenProvider>(),
|
|
operationBloc: context.read<OperationBloc>(),
|
|
)
|
|
// Beim ersten Build: prüfen, ob ein
|
|
// Refresh-Token aus der Secure Storage da ist,
|
|
// und ggf. direkt einloggen.
|
|
..add(const RestoreSessionRequested()),
|
|
),
|
|
BlocProvider(
|
|
create:
|
|
(context) => TourBloc(
|
|
opBloc: context.read<OperationBloc>(),
|
|
authBloc: context.read<AuthBloc>(),
|
|
tourRepository: TourRepository(
|
|
service: TourService(),
|
|
),
|
|
),
|
|
),
|
|
BlocProvider(
|
|
create: (context) =>
|
|
CarSelectBloc(repository: CarSelectionRepository()),
|
|
),
|
|
BlocProvider(
|
|
// Phase-D-Migration: produktive CarsRepository-Impl
|
|
// gegen das generierte Rust-Backend-API. Account-Filter
|
|
// serverseitig aus dem JWT, deshalb braucht der Bloc
|
|
// keinen AuthBloc-Bezug mehr.
|
|
create: (context) => CarsBloc(
|
|
repository: CarsRepositoryImpl(locator<HolzleitnerApi>()),
|
|
opBloc: context.read<OperationBloc>(),
|
|
),
|
|
),
|
|
BlocProvider(
|
|
// PhaseBloc darf erst NACH dem TourBloc gebaut werden,
|
|
// da er die Anzahl der Team-Fahrzeuge daraus liest, um
|
|
// beim ersten Load eines Fahrzeugs die korrekte
|
|
// Eintrittsphase (Auswählen vs. Sortieren) zu bestimmen.
|
|
create: (context) => PhaseBloc(
|
|
carCountResolver: () {
|
|
final tourState = context.read<TourBloc>().state;
|
|
return tourState is TourLoaded
|
|
? tourState.tour.driver.cars.length
|
|
: null;
|
|
},
|
|
),
|
|
),
|
|
],
|
|
child: MaterialApp(
|
|
// Wrap the Navigator (not just the home route) so the loading
|
|
// overlay covers every pushed route — DeliveryDetail, Cars,
|
|
// dialogs, etc. — not only the initial home tree.
|
|
builder: (context, child) =>
|
|
OperationViewEnforcer(child: child ?? const SizedBox.shrink()),
|
|
home: BlocBuilder<AppBloc, AppState>(
|
|
builder: (context, state) {
|
|
if (state is AppConfigLoading) {
|
|
return Scaffold(
|
|
body: Center(child: CircularProgressIndicator()),
|
|
);
|
|
}
|
|
|
|
if (state is AppConfigLoadingFailed) {
|
|
return Scaffold(body: Center(child: Text(state.message)));
|
|
}
|
|
|
|
if (state is AppConfigLoaded) {
|
|
return LoginEnforcer(
|
|
child: CarSelectionEnforcer(child: Home()),
|
|
);
|
|
}
|
|
|
|
return Container();
|
|
},
|
|
),
|
|
routes: {"/cars": (context) => CarManagementPage()},
|
|
),
|
|
);
|
|
}
|
|
|
|
if (state is AppConfigLoadingFailed) {
|
|
return MaterialApp(
|
|
home: Scaffold(
|
|
body: Center(child: Text("Fehler beim Laden der Konfiguration")),
|
|
),
|
|
);
|
|
}
|
|
|
|
return MaterialApp(
|
|
home: Scaffold(
|
|
body: Center(child: const CircularProgressIndicator()),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|