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:
43
lib/feature/cars/presentation/car_fail_page.dart
Normal file
43
lib/feature/cars/presentation/car_fail_page.dart
Normal file
@ -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/cars/bloc/cars_bloc.dart';
|
||||||
|
import 'package:hl_lieferservice/feature/cars/bloc/cars_event.dart';
|
||||||
|
|
||||||
|
class CarsLoadingFailedPage extends StatelessWidget {
|
||||||
|
const CarsLoadingFailedPage({super.key});
|
||||||
|
|
||||||
|
void _onRetry(BuildContext context) {
|
||||||
|
Authenticated state = context.read<AuthBloc>().state as Authenticated;
|
||||||
|
context.read<CarsBloc>().add(CarLoad(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 Fahrzeuge zu einem Fehler gekommen.",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 30),
|
||||||
|
child: FilledButton(
|
||||||
|
onPressed: () => _onRetry(context),
|
||||||
|
child: Text("Erneut versuchen"),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,6 +5,7 @@ import 'package:hl_lieferservice/feature/authentication/bloc/auth_state.dart';
|
|||||||
import 'package:hl_lieferservice/feature/cars/bloc/cars_bloc.dart';
|
import 'package:hl_lieferservice/feature/cars/bloc/cars_bloc.dart';
|
||||||
import 'package:hl_lieferservice/feature/cars/bloc/cars_event.dart';
|
import 'package:hl_lieferservice/feature/cars/bloc/cars_event.dart';
|
||||||
import 'package:hl_lieferservice/feature/cars/bloc/cars_state.dart';
|
import 'package:hl_lieferservice/feature/cars/bloc/cars_state.dart';
|
||||||
|
import 'package:hl_lieferservice/feature/cars/presentation/car_fail_page.dart';
|
||||||
import 'package:hl_lieferservice/feature/cars/presentation/car_management.dart';
|
import 'package:hl_lieferservice/feature/cars/presentation/car_management.dart';
|
||||||
import 'package:hl_lieferservice/feature/delivery/bloc/tour_bloc.dart';
|
import 'package:hl_lieferservice/feature/delivery/bloc/tour_bloc.dart';
|
||||||
import 'package:hl_lieferservice/feature/delivery/bloc/tour_event.dart';
|
import 'package:hl_lieferservice/feature/delivery/bloc/tour_event.dart';
|
||||||
@ -76,9 +77,7 @@ class _CarManagementPageState extends State<CarManagementPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (state is CarsLoadingFailed) {
|
if (state is CarsLoadingFailed) {
|
||||||
return Center(
|
return CarsLoadingFailedPage();
|
||||||
child: const Text("Fahrzeuge konnten nicht geladen werden"),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Container();
|
return Container();
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.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_event.dart';
|
||||||
import 'package:hl_lieferservice/feature/delivery/bloc/tour_state.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/repository/tour_repository.dart';
|
||||||
import 'package:hl_lieferservice/feature/delivery/overview/service/distance_service.dart';
|
import 'package:hl_lieferservice/feature/delivery/overview/service/distance_service.dart';
|
||||||
import 'package:hl_lieferservice/feature/delivery/overview/service/reorder_service.dart';
|
import 'package:hl_lieferservice/feature/delivery/overview/service/reorder_service.dart';
|
||||||
@ -128,39 +127,44 @@ class TourBloc extends Bloc<TourEvent, TourState> {
|
|||||||
) async {
|
) async {
|
||||||
Map<String, double> distances = {};
|
Map<String, double> distances = {};
|
||||||
opBloc.add(LoadOperation());
|
opBloc.add(LoadOperation());
|
||||||
|
|
||||||
emit(TourRequestingDistances(tour: event.tour, payments: event.payments));
|
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(
|
distances[delivery.id] = await DistanceService.getDistanceByRoad(
|
||||||
delivery.customer.address.toString(),
|
delivery.customer.address.toString(),
|
||||||
);
|
);
|
||||||
}
|
} catch (e,st) {
|
||||||
|
debugPrint("Fehler beim Laden der Distanz: $e");
|
||||||
|
debugPrint("$st");
|
||||||
|
|
||||||
opBloc.add(FinishOperation());
|
// set the distance to none in order to handle the error case
|
||||||
} catch (e) {
|
// afterwards for that specific delivery
|
||||||
debugPrint("Fehler beim Berechnen der Distanzen: $e");
|
distances[delivery.id] = double.nan;
|
||||||
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,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(
|
void _requestSortingInformation(
|
||||||
RequestSortingInformationEvent event,
|
RequestSortingInformationEvent event,
|
||||||
Emitter<TourState> emit,
|
Emitter<TourState> emit,
|
||||||
) async {
|
) async {
|
||||||
|
Map<String, List<String>> container = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ReorderService service = ReorderService();
|
ReorderService service = ReorderService();
|
||||||
Map<String, List<String>> container = {};
|
|
||||||
|
|
||||||
// Create empty default value if it does not exist yet
|
// Create empty default value if it does not exist yet
|
||||||
if (!service.orderInformationExist()) {
|
if (!service.orderInformationExist()) {
|
||||||
@ -189,15 +193,6 @@ class TourBloc extends Bloc<TourEvent, TourState> {
|
|||||||
if (inconsistent) {
|
if (inconsistent) {
|
||||||
await service.saveSortingInformation(container);
|
await service.saveSortingInformation(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
emit(
|
|
||||||
TourLoaded(
|
|
||||||
tour: event.tour,
|
|
||||||
paymentOptions: event.payments,
|
|
||||||
sortingInformation: container,
|
|
||||||
distances: event.distances,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
debugPrint("Fehler beim Lesen der Datei: $e");
|
debugPrint("Fehler beim Lesen der Datei: $e");
|
||||||
debugPrint("$st");
|
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) {
|
for (final delivery in event.tour.deliveries) {
|
||||||
container[delivery.carId.toString()]!.add(delivery.id);
|
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) {
|
void _updated(TourUpdated event, Emitter<TourState> emit) {
|
||||||
@ -392,6 +387,9 @@ class TourBloc extends Bloc<TourEvent, TourState> {
|
|||||||
|
|
||||||
opBloc.add(FinishOperation());
|
opBloc.add(FinishOperation());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
// go to the error state in order to give the user the chance
|
||||||
|
// to reload if necessary.
|
||||||
|
emit(TourLoadingFailed());
|
||||||
opBloc.add(
|
opBloc.add(
|
||||||
FailOperation(message: "Fehler beim Laden der heutigen Fahrten"),
|
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';
|
import '../../../../model/tour.dart';
|
||||||
|
|
||||||
abstract class TourState {}
|
abstract class TourState {}
|
||||||
@ -8,6 +6,8 @@ class TourInitial extends TourState {}
|
|||||||
|
|
||||||
class TourLoading extends TourState {}
|
class TourLoading extends TourState {}
|
||||||
|
|
||||||
|
class TourLoadingFailed extends TourState {}
|
||||||
|
|
||||||
class TourRequestingDistances extends TourState {
|
class TourRequestingDistances extends TourState {
|
||||||
Tour tour;
|
Tour tour;
|
||||||
List<Payment> payments;
|
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/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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_bloc.dart';
|
||||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/note_event.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/bloc/note_state.dart';
|
||||||
import 'package:hl_lieferservice/feature/delivery/detail/model/note.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/feature/delivery/detail/presentation/note/note_overview.dart';
|
||||||
import 'package:hl_lieferservice/model/delivery.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));
|
context.read<NoteBloc>().add(LoadNote(delivery: widget.delivery));
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _notesLoadingFailed() {
|
|
||||||
return Center(child: Text("Notizen können nicht heruntergeladen werden.."));
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _notesLoading() {
|
Widget _notesLoading() {
|
||||||
return Center(child: CircularProgressIndicator());
|
return Center(child: CircularProgressIndicator());
|
||||||
}
|
}
|
||||||
@ -80,7 +76,7 @@ class _DeliveryStepInfo extends State<DeliveryStepNote> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (state is NoteLoadingFailed) {
|
if (state is NoteLoadingFailed) {
|
||||||
return _notesLoadingFailed();
|
return NoteLoadingFailPage(delivery: widget.delivery);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _blocUndefinedState();
|
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/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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 'package:hl_lieferservice/feature/delivery/overview/presentation/delivery_overview.dart';
|
||||||
|
|
||||||
import '../../bloc/tour_bloc.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();
|
return Container();
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,94 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import '../model/article.dart';
|
|
||||||
|
|
||||||
class ArticleOverview extends StatefulWidget {
|
|
||||||
const ArticleOverview({super.key, required this.articleGroups});
|
|
||||||
|
|
||||||
final Map<String, ArticleGroup> articleGroups;
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<StatefulWidget> createState() => _ArticleOverviewState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ArticleOverviewState extends State<ArticleOverview> {
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final sortedArticles =
|
|
||||||
widget.articleGroups.values.toList()
|
|
||||||
..sort((a, b) => a.articleName.compareTo(b.articleName));
|
|
||||||
|
|
||||||
return sortedArticles.isEmpty
|
|
||||||
? Center(
|
|
||||||
child: Text(
|
|
||||||
'Keine Artikel zum Scannen vorhanden',
|
|
||||||
style: TextStyle(fontSize: 18),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: ListView.separated(
|
|
||||||
shrinkWrap: true,
|
|
||||||
physics: NeverScrollableScrollPhysics(),
|
|
||||||
itemCount: sortedArticles.length,
|
|
||||||
separatorBuilder: (context, index) => Divider(height: 0, color: Theme.of(context).colorScheme.surfaceContainerHighest),
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final group = sortedArticles[index];
|
|
||||||
|
|
||||||
return ListTile(
|
|
||||||
leading:
|
|
||||||
group.isComplete
|
|
||||||
? Icon(Icons.check_circle, color: Colors.green, size: 32)
|
|
||||||
: Container(
|
|
||||||
width: 32,
|
|
||||||
alignment: Alignment.center,
|
|
||||||
child: Text(
|
|
||||||
'${group.scannedCount}/${group.totalCount}',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color:
|
|
||||||
group.scannedCount > 0
|
|
||||||
? Colors.blue
|
|
||||||
: Colors.grey,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
title: Text(
|
|
||||||
"${group.articleName} (Artikelnr. ${group.articleNumber})",
|
|
||||||
style: TextStyle(fontWeight: FontWeight.w500),
|
|
||||||
),
|
|
||||||
subtitle: Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 10, bottom: 10),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children:
|
|
||||||
group.deliveryIds
|
|
||||||
.map(
|
|
||||||
(delivery) => Row(
|
|
||||||
children: [
|
|
||||||
Icon(Icons.person),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 5, bottom: 10),
|
|
||||||
child: Text(
|
|
||||||
"${delivery.customer.name.toString()}\n${delivery.customer.address.toString()}",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.toList(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
tileColor:
|
|
||||||
group.isComplete
|
|
||||||
? Colors.green.withValues(alpha: 0.1)
|
|
||||||
: Theme.of(context).colorScheme.onSecondary,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:hl_lieferservice/feature/delivery/bloc/tour_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/bloc/tour_state.dart';
|
||||||
|
import 'package:hl_lieferservice/feature/delivery/overview/presentation/delivery_fail_page.dart';
|
||||||
import 'package:hl_lieferservice/feature/scan/presentation/scan_screen.dart';
|
import 'package:hl_lieferservice/feature/scan/presentation/scan_screen.dart';
|
||||||
import 'package:hl_lieferservice/model/delivery.dart';
|
import 'package:hl_lieferservice/model/delivery.dart';
|
||||||
import 'package:hl_lieferservice/model/tour.dart';
|
import 'package:hl_lieferservice/model/tour.dart';
|
||||||
@ -18,15 +19,13 @@ class ScanPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ScanPageState extends State<ScanPage> {
|
class _ScanPageState extends State<ScanPage> {
|
||||||
int _currentStepIndex = 0;
|
int _currentStepIndex = 1;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
_tryFinish(context
|
_tryFinish(context.read<TourBloc>().state);
|
||||||
.read<TourBloc>()
|
|
||||||
.state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onStartScan() {
|
void _onStartScan() {
|
||||||
@ -37,7 +36,9 @@ class _ScanPageState extends State<ScanPage> {
|
|||||||
|
|
||||||
Widget _tourSteps(Tour tour) {
|
Widget _tourSteps(Tour tour) {
|
||||||
var allArticlesScanned = tour.deliveries.every(
|
var allArticlesScanned = tour.deliveries.every(
|
||||||
(delivery) => delivery.allArticlesScanned() || delivery.state == DeliveryState.finished,
|
(delivery) =>
|
||||||
|
delivery.allArticlesScanned() ||
|
||||||
|
delivery.state == DeliveryState.finished,
|
||||||
);
|
);
|
||||||
|
|
||||||
return Stepper(
|
return Stepper(
|
||||||
@ -63,11 +64,11 @@ class _ScanPageState extends State<ScanPage> {
|
|||||||
child: FilledButton.icon(
|
child: FilledButton.icon(
|
||||||
label: const Text("Auslieferung starten"),
|
label: const Text("Auslieferung starten"),
|
||||||
onPressed:
|
onPressed:
|
||||||
allArticlesScanned
|
allArticlesScanned
|
||||||
? () =>
|
? () => context.read<NavigationBloc>().add(
|
||||||
context.read<NavigationBloc>().add(
|
NavigateToIndex(index: 1),
|
||||||
NavigateToIndex(index: 1))
|
)
|
||||||
: null,
|
: null,
|
||||||
icon: const Icon(Icons.local_shipping),
|
icon: const Icon(Icons.local_shipping),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -75,26 +76,23 @@ class _ScanPageState extends State<ScanPage> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onStepContinue:
|
onStepContinue:
|
||||||
_currentStepIndex >= 1
|
_currentStepIndex >= 1
|
||||||
? null
|
? null
|
||||||
: () =>
|
: () => setState(() {
|
||||||
setState(() {
|
if (_currentStepIndex < 2) {
|
||||||
if (_currentStepIndex < 2) {
|
_currentStepIndex += 1;
|
||||||
_currentStepIndex += 1;
|
}
|
||||||
}
|
}),
|
||||||
}),
|
|
||||||
onStepCancel:
|
onStepCancel:
|
||||||
_currentStepIndex == 0
|
_currentStepIndex == 0
|
||||||
? null
|
? null
|
||||||
: () =>
|
: () => setState(() {
|
||||||
setState(() {
|
if (_currentStepIndex > 0) {
|
||||||
if (_currentStepIndex > 0) {
|
_currentStepIndex -= 1;
|
||||||
_currentStepIndex -= 1;
|
}
|
||||||
}
|
}),
|
||||||
}),
|
|
||||||
onStepTapped:
|
onStepTapped:
|
||||||
(value) =>
|
(value) => setState(() {
|
||||||
setState(() {
|
|
||||||
if (_currentStepIndex == 1 && allArticlesScanned) {
|
if (_currentStepIndex == 1 && allArticlesScanned) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -114,15 +112,15 @@ class _ScanPageState extends State<ScanPage> {
|
|||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(left: 5),
|
padding: const EdgeInsets.only(left: 5),
|
||||||
child:
|
child:
|
||||||
!allArticlesScanned
|
!allArticlesScanned
|
||||||
? const Icon(
|
? const Icon(
|
||||||
Icons.access_time_filled,
|
Icons.access_time_filled,
|
||||||
color: Colors.orangeAccent,
|
color: Colors.orangeAccent,
|
||||||
)
|
)
|
||||||
: const Icon(
|
: const Icon(
|
||||||
Icons.check_circle,
|
Icons.check_circle,
|
||||||
color: Colors.lightGreen,
|
color: Colors.lightGreen,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -143,11 +141,11 @@ class _ScanPageState extends State<ScanPage> {
|
|||||||
content: Container(
|
content: Container(
|
||||||
alignment: Alignment.centerLeft,
|
alignment: Alignment.centerLeft,
|
||||||
child:
|
child:
|
||||||
!allArticlesScanned
|
!allArticlesScanned
|
||||||
? const Text(
|
? const Text(
|
||||||
"Scannen Sie erst die benötigte Ware, um die Auslieferungen zu beginnen.",
|
"Scannen Sie erst die benötigte Ware, um die Auslieferungen zu beginnen.",
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -157,14 +155,14 @@ class _ScanPageState extends State<ScanPage> {
|
|||||||
Widget _info(Tour tour) {
|
Widget _info(Tour tour) {
|
||||||
int amountArticles = tour.deliveries.fold(
|
int amountArticles = tour.deliveries.fold(
|
||||||
0,
|
0,
|
||||||
(acc, delivery) =>
|
(acc, delivery) =>
|
||||||
acc +
|
acc +
|
||||||
delivery.articles
|
delivery.articles
|
||||||
.where((article) => article.scannable)
|
.where((article) => article.scannable)
|
||||||
.fold(
|
.fold(
|
||||||
0,
|
0,
|
||||||
(amountArticles, article) => amountArticles + article.amount,
|
(amountArticles, article) => amountArticles + article.amount,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
int amountCars = tour.driver.cars.length;
|
int amountCars = tour.driver.cars.length;
|
||||||
@ -175,10 +173,7 @@ class _ScanPageState extends State<ScanPage> {
|
|||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
child: Card(
|
child: Card(
|
||||||
color: Theme
|
color: Theme.of(context).colorScheme.onSecondary,
|
||||||
.of(context)
|
|
||||||
.colorScheme
|
|
||||||
.onSecondary,
|
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(20),
|
padding: const EdgeInsets.all(20),
|
||||||
child: Column(
|
child: Column(
|
||||||
@ -250,11 +245,11 @@ class _ScanPageState extends State<ScanPage> {
|
|||||||
|
|
||||||
void _tryFinish(TourState state) {
|
void _tryFinish(TourState state) {
|
||||||
if (state is TourLoaded) {
|
if (state is TourLoaded) {
|
||||||
if (state.tour.deliveries.every(
|
if (!state.tour.deliveries
|
||||||
(delivery) => delivery.allArticlesScanned(),
|
.where((delivery) => delivery.state == DeliveryState.ongoing)
|
||||||
)) {
|
.every((delivery) => delivery.allArticlesScanned())) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_currentStepIndex = 1;
|
_currentStepIndex = 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -271,6 +266,10 @@ class _ScanPageState extends State<ScanPage> {
|
|||||||
return Column(children: [_info(state.tour), _tourSteps(state.tour)]);
|
return Column(children: [_info(state.tour), _tourSteps(state.tour)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (state is TourLoadingFailed) {
|
||||||
|
return DeliveryLoadingFailedPage();
|
||||||
|
}
|
||||||
|
|
||||||
return Center(child: CircularProgressIndicator());
|
return Center(child: CircularProgressIndicator());
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@ -13,9 +13,11 @@ import 'package:hl_lieferservice/model/article.dart';
|
|||||||
import 'package:hl_lieferservice/model/car.dart';
|
import 'package:hl_lieferservice/model/car.dart';
|
||||||
import 'package:hl_lieferservice/model/delivery.dart';
|
import 'package:hl_lieferservice/model/delivery.dart';
|
||||||
import 'package:hl_lieferservice/model/tour.dart';
|
import 'package:hl_lieferservice/model/tour.dart';
|
||||||
|
import 'package:hl_lieferservice/widget/home/bloc/navigation_event.dart';
|
||||||
import 'package:hl_lieferservice/widget/operations/bloc/operation_bloc.dart';
|
import 'package:hl_lieferservice/widget/operations/bloc/operation_bloc.dart';
|
||||||
import 'package:hl_lieferservice/widget/operations/bloc/operation_event.dart';
|
import 'package:hl_lieferservice/widget/operations/bloc/operation_event.dart';
|
||||||
|
|
||||||
|
import '../../../widget/home/bloc/navigation_bloc.dart';
|
||||||
import '../../delivery/bloc/tour_bloc.dart';
|
import '../../delivery/bloc/tour_bloc.dart';
|
||||||
|
|
||||||
class ArticleScanningScreen extends StatefulWidget {
|
class ArticleScanningScreen extends StatefulWidget {
|
||||||
@ -287,7 +289,9 @@ class _ArticleScanningScreenState extends State<ArticleScanningScreen> {
|
|||||||
isExpanded: true,
|
isExpanded: true,
|
||||||
items:
|
items:
|
||||||
deliveries
|
deliveries
|
||||||
.where((delivery) => delivery.state != DeliveryState.finished)
|
.where(
|
||||||
|
(delivery) => delivery.state != DeliveryState.finished,
|
||||||
|
)
|
||||||
.mapIndexed(
|
.mapIndexed(
|
||||||
(index, delivery) => DropdownMenuItem(
|
(index, delivery) => DropdownMenuItem(
|
||||||
value: index,
|
value: index,
|
||||||
@ -343,6 +347,45 @@ class _ArticleScanningScreenState extends State<ArticleScanningScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Also count aborted or hold deliveries as "delivered"
|
||||||
|
final allDeliveredOrAllScanned = tour.deliveries
|
||||||
|
.where((delivery) => delivery.state != DeliveryState.finished)
|
||||||
|
.every((delivery) => delivery.allArticlesScanned());
|
||||||
|
|
||||||
|
if (allDeliveredOrAllScanned) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(25),
|
||||||
|
child: Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 25),
|
||||||
|
child: Icon(
|
||||||
|
Icons.check_circle_outline,
|
||||||
|
size: 72,
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text("Alles erledigt - es gibt nichts mehr zu scannen!"),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 25),
|
||||||
|
child: FilledButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
context.read<NavigationBloc>().add(
|
||||||
|
NavigateToIndex(index: 1),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: Text("Tour starten"),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(0),
|
padding: const EdgeInsets.all(0),
|
||||||
child: Column(
|
child: Column(
|
||||||
@ -363,34 +406,57 @@ class _ArticleScanningScreenState extends State<ArticleScanningScreen> {
|
|||||||
if (state is TourLoaded) {
|
if (state is TourLoaded) {
|
||||||
Delivery delivery = state.tour.deliveries[_selectedDelivery];
|
Delivery delivery = state.tour.deliveries[_selectedDelivery];
|
||||||
|
|
||||||
|
// Also count aborted or hold deliveries as "delivered"
|
||||||
|
final allDeliveredOrAllScanned = state.tour.deliveries
|
||||||
|
.where((delivery) => delivery.state != DeliveryState.finished)
|
||||||
|
.every((delivery) => delivery.allArticlesScanned());
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Column(
|
title:
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
allDeliveredOrAllScanned
|
||||||
children: [
|
? Text(
|
||||||
Text(
|
"Artikel scannen",
|
||||||
delivery.customer.name,
|
style: TextStyle(
|
||||||
style: TextStyle(
|
color: Theme.of(context).colorScheme.onSecondary,
|
||||||
color: Theme.of(context).colorScheme.onSecondary,
|
),
|
||||||
fontWeight: FontWeight.w500,
|
)
|
||||||
),
|
: Column(
|
||||||
),
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
Text(
|
children: [
|
||||||
delivery.customer.address.toString(),
|
Text(
|
||||||
style: TextStyle(
|
delivery.customer.name,
|
||||||
fontSize: 14,
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.normal,
|
color: Theme.of(context).colorScheme.onSecondary,
|
||||||
color: Theme.of(context).colorScheme.onSecondary,
|
fontWeight: FontWeight.w500,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
Text(
|
||||||
),
|
delivery.customer.address.toString(),
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.normal,
|
||||||
|
color: Theme.of(context).colorScheme.onSecondary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
backgroundColor: Theme.of(context).primaryColor,
|
backgroundColor: Theme.of(context).primaryColor,
|
||||||
),
|
),
|
||||||
bottomNavigationBar: Padding(
|
bottomNavigationBar:
|
||||||
padding: const EdgeInsets.all(25),
|
allDeliveredOrAllScanned
|
||||||
child: _navigation(state.tour.deliveries),
|
? Text("")
|
||||||
),
|
: Padding(
|
||||||
|
padding: const EdgeInsets.all(25),
|
||||||
|
child: _navigation(
|
||||||
|
state.tour.deliveries
|
||||||
|
.where(
|
||||||
|
(delivery) =>
|
||||||
|
delivery.state == DeliveryState.ongoing,
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
|
),
|
||||||
|
),
|
||||||
body: KeyboardListener(
|
body: KeyboardListener(
|
||||||
focusNode: _focusNode,
|
focusNode: _focusNode,
|
||||||
onKeyEvent: _handleKey,
|
onKeyEvent: _handleKey,
|
||||||
|
|||||||
Reference in New Issue
Block a user