Added fail pages to retry the failed operation to delivery overview, notes and cars. Furthermore, I added better handling if the user is finished scanning articles.

This commit is contained in:
Dennis Nemec
2026-01-29 16:45:29 +01:00
parent 366a3560dc
commit 8cf0ea4e9a
11 changed files with 319 additions and 223 deletions

View File

@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hl_lieferservice/feature/delivery/bloc/tour_event.dart';
import 'package:hl_lieferservice/feature/delivery/bloc/tour_state.dart';
import 'package:hl_lieferservice/feature/delivery/overview/model/sorting_information.dart';
import 'package:hl_lieferservice/feature/delivery/repository/tour_repository.dart';
import 'package:hl_lieferservice/feature/delivery/overview/service/distance_service.dart';
import 'package:hl_lieferservice/feature/delivery/overview/service/reorder_service.dart';
@ -128,39 +127,44 @@ class TourBloc extends Bloc<TourEvent, TourState> {
) async {
Map<String, double> distances = {};
opBloc.add(LoadOperation());
emit(TourRequestingDistances(tour: event.tour, payments: event.payments));
try {
for (final delivery in event.tour.deliveries) {
for (final delivery in event.tour.deliveries) {
try {
distances[delivery.id] = await DistanceService.getDistanceByRoad(
delivery.customer.address.toString(),
);
}
} catch (e,st) {
debugPrint("Fehler beim Laden der Distanz: $e");
debugPrint("$st");
opBloc.add(FinishOperation());
} catch (e) {
debugPrint("Fehler beim Berechnen der Distanzen: $e");
opBloc.add(FailOperation(message: "Fehler beim Berechnen der Distanzen"));
return;
} finally {
// Independent of error state fetch the sorting information
add(
RequestSortingInformationEvent(
tour: event.tour,
payments: event.payments,
distances: distances,
),
);
// set the distance to none in order to handle the error case
// afterwards for that specific delivery
distances[delivery.id] = double.nan;
}
}
opBloc.add(FinishOperation());
// If an error occurred, then the distances will be empty
// If the distances are empty then they shouldn't be displayed
add(
RequestSortingInformationEvent(
tour: event.tour,
payments: event.payments,
distances: distances,
),
);
}
void _requestSortingInformation(
RequestSortingInformationEvent event,
Emitter<TourState> emit,
) async {
Map<String, List<String>> container = {};
try {
ReorderService service = ReorderService();
Map<String, List<String>> container = {};
// Create empty default value if it does not exist yet
if (!service.orderInformationExist()) {
@ -189,15 +193,6 @@ class TourBloc extends Bloc<TourEvent, TourState> {
if (inconsistent) {
await service.saveSortingInformation(container);
}
emit(
TourLoaded(
tour: event.tour,
paymentOptions: event.payments,
sortingInformation: container,
distances: event.distances,
),
);
} catch (e, st) {
debugPrint("Fehler beim Lesen der Datei: $e");
debugPrint("$st");
@ -209,20 +204,20 @@ class TourBloc extends Bloc<TourEvent, TourState> {
),
);
Map<String, List<String>> container = {};
// fill the container without sorting information
for (final delivery in event.tour.deliveries) {
container[delivery.carId.toString()]!.add(delivery.id);
}
emit(
TourLoaded(
tour: event.tour,
paymentOptions: event.payments,
sortingInformation: container,
distances: event.distances,
),
);
}
emit(
TourLoaded(
tour: event.tour,
paymentOptions: event.payments,
sortingInformation: container,
distances: event.distances,
),
);
}
void _updated(TourUpdated event, Emitter<TourState> emit) {
@ -392,6 +387,9 @@ class TourBloc extends Bloc<TourEvent, TourState> {
opBloc.add(FinishOperation());
} catch (e) {
// go to the error state in order to give the user the chance
// to reload if necessary.
emit(TourLoadingFailed());
opBloc.add(
FailOperation(message: "Fehler beim Laden der heutigen Fahrten"),
);