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

@ -2,6 +2,7 @@ import 'package:flutter/material.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_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/model/delivery.dart';
import 'package:hl_lieferservice/model/tour.dart';
@ -18,15 +19,13 @@ class ScanPage extends StatefulWidget {
}
class _ScanPageState extends State<ScanPage> {
int _currentStepIndex = 0;
int _currentStepIndex = 1;
@override
void initState() {
super.initState();
_tryFinish(context
.read<TourBloc>()
.state);
_tryFinish(context.read<TourBloc>().state);
}
void _onStartScan() {
@ -37,7 +36,9 @@ class _ScanPageState extends State<ScanPage> {
Widget _tourSteps(Tour tour) {
var allArticlesScanned = tour.deliveries.every(
(delivery) => delivery.allArticlesScanned() || delivery.state == DeliveryState.finished,
(delivery) =>
delivery.allArticlesScanned() ||
delivery.state == DeliveryState.finished,
);
return Stepper(
@ -63,11 +64,11 @@ class _ScanPageState extends State<ScanPage> {
child: FilledButton.icon(
label: const Text("Auslieferung starten"),
onPressed:
allArticlesScanned
? () =>
context.read<NavigationBloc>().add(
NavigateToIndex(index: 1))
: null,
allArticlesScanned
? () => context.read<NavigationBloc>().add(
NavigateToIndex(index: 1),
)
: null,
icon: const Icon(Icons.local_shipping),
),
),
@ -75,26 +76,23 @@ class _ScanPageState extends State<ScanPage> {
}
},
onStepContinue:
_currentStepIndex >= 1
? null
: () =>
setState(() {
if (_currentStepIndex < 2) {
_currentStepIndex += 1;
}
}),
_currentStepIndex >= 1
? null
: () => setState(() {
if (_currentStepIndex < 2) {
_currentStepIndex += 1;
}
}),
onStepCancel:
_currentStepIndex == 0
? null
: () =>
setState(() {
if (_currentStepIndex > 0) {
_currentStepIndex -= 1;
}
}),
_currentStepIndex == 0
? null
: () => setState(() {
if (_currentStepIndex > 0) {
_currentStepIndex -= 1;
}
}),
onStepTapped:
(value) =>
setState(() {
(value) => setState(() {
if (_currentStepIndex == 1 && allArticlesScanned) {
return;
}
@ -114,15 +112,15 @@ class _ScanPageState extends State<ScanPage> {
Padding(
padding: const EdgeInsets.only(left: 5),
child:
!allArticlesScanned
? const Icon(
Icons.access_time_filled,
color: Colors.orangeAccent,
)
: const Icon(
Icons.check_circle,
color: Colors.lightGreen,
),
!allArticlesScanned
? const Icon(
Icons.access_time_filled,
color: Colors.orangeAccent,
)
: const Icon(
Icons.check_circle,
color: Colors.lightGreen,
),
),
],
),
@ -143,11 +141,11 @@ class _ScanPageState extends State<ScanPage> {
content: Container(
alignment: Alignment.centerLeft,
child:
!allArticlesScanned
? const Text(
"Scannen Sie erst die benötigte Ware, um die Auslieferungen zu beginnen.",
)
: null,
!allArticlesScanned
? const Text(
"Scannen Sie erst die benötigte Ware, um die Auslieferungen zu beginnen.",
)
: null,
),
),
],
@ -157,14 +155,14 @@ class _ScanPageState extends State<ScanPage> {
Widget _info(Tour tour) {
int amountArticles = tour.deliveries.fold(
0,
(acc, delivery) =>
acc +
(acc, delivery) =>
acc +
delivery.articles
.where((article) => article.scannable)
.fold(
0,
0,
(amountArticles, article) => amountArticles + article.amount,
),
),
);
int amountCars = tour.driver.cars.length;
@ -175,10 +173,7 @@ class _ScanPageState extends State<ScanPage> {
child: SizedBox(
width: double.infinity,
child: Card(
color: Theme
.of(context)
.colorScheme
.onSecondary,
color: Theme.of(context).colorScheme.onSecondary,
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
@ -250,11 +245,11 @@ class _ScanPageState extends State<ScanPage> {
void _tryFinish(TourState state) {
if (state is TourLoaded) {
if (state.tour.deliveries.every(
(delivery) => delivery.allArticlesScanned(),
)) {
if (!state.tour.deliveries
.where((delivery) => delivery.state == DeliveryState.ongoing)
.every((delivery) => delivery.allArticlesScanned())) {
setState(() {
_currentStepIndex = 1;
_currentStepIndex = 0;
});
}
}
@ -271,6 +266,10 @@ class _ScanPageState extends State<ScanPage> {
return Column(children: [_info(state.tour), _tourSteps(state.tour)]);
}
if (state is TourLoadingFailed) {
return DeliveryLoadingFailedPage();
}
return Center(child: CircularProgressIndicator());
},
);