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:
@ -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"),
|
||||
);
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/model/sorting_information.dart';
|
||||
|
||||
import '../../../../model/tour.dart';
|
||||
|
||||
abstract class TourState {}
|
||||
@ -8,6 +6,8 @@ class TourInitial extends TourState {}
|
||||
|
||||
class TourLoading extends TourState {}
|
||||
|
||||
class TourLoadingFailed extends TourState {}
|
||||
|
||||
class TourRequestingDistances extends TourState {
|
||||
Tour tour;
|
||||
List<Payment> payments;
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/note_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/note_event.dart';
|
||||
import 'package:hl_lieferservice/model/delivery.dart';
|
||||
|
||||
class NoteLoadingFailPage extends StatelessWidget {
|
||||
const NoteLoadingFailPage({super.key, required this.delivery});
|
||||
|
||||
final Delivery delivery;
|
||||
|
||||
void _onRetry(BuildContext context) {
|
||||
context.read<NoteBloc>().add(LoadNote(delivery: delivery));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(50),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.error_outline, size: 72, color: Theme.of(context).colorScheme.error,),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 30),
|
||||
child: Text(
|
||||
"Leider ist es beim Laden der Notizen zu einem Fehler gekommen.",
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 30),
|
||||
child: FilledButton(
|
||||
onPressed: () => _onRetry(context),
|
||||
child: Text("Erneut versuchen"),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,10 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/note_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/note_event.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/note_state.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/model/note.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/presentation/note/note_fail_page.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/presentation/note/note_overview.dart';
|
||||
import 'package:hl_lieferservice/model/delivery.dart';
|
||||
|
||||
@ -24,10 +24,6 @@ class _DeliveryStepInfo extends State<DeliveryStepNote> {
|
||||
context.read<NoteBloc>().add(LoadNote(delivery: widget.delivery));
|
||||
}
|
||||
|
||||
Widget _notesLoadingFailed() {
|
||||
return Center(child: Text("Notizen können nicht heruntergeladen werden.."));
|
||||
}
|
||||
|
||||
Widget _notesLoading() {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
@ -80,7 +76,7 @@ class _DeliveryStepInfo extends State<DeliveryStepNote> {
|
||||
}
|
||||
|
||||
if (state is NoteLoadingFailed) {
|
||||
return _notesLoadingFailed();
|
||||
return NoteLoadingFailPage(delivery: widget.delivery);
|
||||
}
|
||||
|
||||
return _blocUndefinedState();
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/authentication/bloc/auth_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/authentication/bloc/auth_state.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/bloc/tour_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/bloc/tour_event.dart';
|
||||
|
||||
class DeliveryLoadingFailedPage extends StatelessWidget {
|
||||
const DeliveryLoadingFailedPage({super.key});
|
||||
|
||||
void _onRetry(BuildContext context) {
|
||||
Authenticated state = context.read<AuthBloc>().state as Authenticated;
|
||||
context.read<TourBloc>().add(LoadTour(teamId: state.user.number));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(50),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.error_outline, size: 72, color: Theme.of(context).colorScheme.error,),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 30),
|
||||
child: Text(
|
||||
"Leider ist es beim Laden der Fahrten zu einem Fehler gekommen.",
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 30),
|
||||
child: FilledButton(
|
||||
onPressed: () => _onRetry(context),
|
||||
child: Text("Erneut versuchen"),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/presentation/delivery_fail_page.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/presentation/delivery_overview.dart';
|
||||
|
||||
import '../../bloc/tour_bloc.dart';
|
||||
@ -28,7 +29,9 @@ class _DeliveryOverviewPageState extends State<DeliveryOverviewPage> {
|
||||
);
|
||||
}
|
||||
|
||||
debugPrint(state.toString());
|
||||
if (state is TourLoadingFailed) {
|
||||
return DeliveryLoadingFailedPage();
|
||||
}
|
||||
|
||||
return Container();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user