Implemented new set article mechanism for unscannable articles

This commit is contained in:
Dennis Nemec
2026-01-10 20:20:28 +01:00
parent 1848f47e7f
commit 2436177c95
17 changed files with 334 additions and 46 deletions

View File

@ -5,7 +5,7 @@ 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/overview/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/reorder_service.dart';
import 'package:hl_lieferservice/model/tour.dart';
@ -55,6 +55,7 @@ class TourBloc extends Bloc<TourEvent, TourState> {
on<RequestSortingInformationEvent>(_requestSortingInformation);
on<ReorderDeliveryEvent>(_reorderDelivery);
on<CarsLoadedEvent>(_carsLoaded);
on<SetArticleAmountEvent>(_setArticleAmount);
}
@override
@ -64,6 +65,33 @@ class TourBloc extends Bloc<TourEvent, TourState> {
return super.close();
}
void _setArticleAmount(
SetArticleAmountEvent event,
Emitter<TourState> emit,
) async {
final currentState = state;
if (currentState is TourLoaded) {
opBloc.add(LoadOperation());
try {
await tourRepository.setArticleAmount(
event.deliveryId,
event.articleId,
event.amount,
event.reason
);
opBloc.add(FinishOperation());
} catch (e, st) {
opBloc.add(
FailOperation(message: "Fehler beim Ändern der Menge des Artikels"),
);
debugPrint("$e");
debugPrint("$st");
}
}
}
void _carsLoaded(CarsLoadedEvent event, Emitter<TourState> emit) {
final currentState = state;
if (currentState is TourLoaded) {
@ -78,13 +106,16 @@ class TourBloc extends Bloc<TourEvent, TourState> {
) async {
final currentState = state;
if (currentState is TourLoaded) {
int newPosition = event.newPosition == currentState.sortingInformation.sorting.length ? event.newPosition - 1 : event.newPosition;
SortingInformation informationOld = currentState.sortingInformation.sorting
.firstWhere((info) => info.position == event.oldPosition);
SortingInformation information = currentState
int newPosition =
event.newPosition == currentState.sortingInformation.sorting.length
? event.newPosition - 1
: event.newPosition;
SortingInformation informationOld = currentState
.sortingInformation
.sorting
.firstWhere((info) => info.position == event.oldPosition);
SortingInformation information = currentState.sortingInformation.sorting
.firstWhere((info) => info.position == newPosition);
information.position = event.oldPosition;