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:
@ -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: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());
|
||||
},
|
||||
);
|
||||
|
||||
@ -13,9 +13,11 @@ import 'package:hl_lieferservice/model/article.dart';
|
||||
import 'package:hl_lieferservice/model/car.dart';
|
||||
import 'package:hl_lieferservice/model/delivery.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_event.dart';
|
||||
|
||||
import '../../../widget/home/bloc/navigation_bloc.dart';
|
||||
import '../../delivery/bloc/tour_bloc.dart';
|
||||
|
||||
class ArticleScanningScreen extends StatefulWidget {
|
||||
@ -287,7 +289,9 @@ class _ArticleScanningScreenState extends State<ArticleScanningScreen> {
|
||||
isExpanded: true,
|
||||
items:
|
||||
deliveries
|
||||
.where((delivery) => delivery.state != DeliveryState.finished)
|
||||
.where(
|
||||
(delivery) => delivery.state != DeliveryState.finished,
|
||||
)
|
||||
.mapIndexed(
|
||||
(index, delivery) => DropdownMenuItem(
|
||||
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(
|
||||
padding: const EdgeInsets.all(0),
|
||||
child: Column(
|
||||
@ -363,34 +406,57 @@ class _ArticleScanningScreenState extends State<ArticleScanningScreen> {
|
||||
if (state is TourLoaded) {
|
||||
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(
|
||||
appBar: AppBar(
|
||||
title: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
delivery.customer.name,
|
||||
style: TextStyle(
|
||||
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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
title:
|
||||
allDeliveredOrAllScanned
|
||||
? Text(
|
||||
"Artikel scannen",
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onSecondary,
|
||||
),
|
||||
)
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
delivery.customer.name,
|
||||
style: TextStyle(
|
||||
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,
|
||||
),
|
||||
bottomNavigationBar: Padding(
|
||||
padding: const EdgeInsets.all(25),
|
||||
child: _navigation(state.tour.deliveries),
|
||||
),
|
||||
bottomNavigationBar:
|
||||
allDeliveredOrAllScanned
|
||||
? Text("")
|
||||
: Padding(
|
||||
padding: const EdgeInsets.all(25),
|
||||
child: _navigation(
|
||||
state.tour.deliveries
|
||||
.where(
|
||||
(delivery) =>
|
||||
delivery.state == DeliveryState.ongoing,
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
body: KeyboardListener(
|
||||
focusNode: _focusNode,
|
||||
onKeyEvent: _handleKey,
|
||||
|
||||
Reference in New Issue
Block a user