This commit is contained in:
Dennis Nemec
2026-04-28 13:03:09 +02:00
parent de8668c11a
commit 2470299a10
53 changed files with 2409 additions and 1433 deletions

View File

@ -3,6 +3,9 @@ import 'dart:typed_data';
import 'package:flutter/cupertino.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_event.dart';
import 'package:hl_lieferservice/feature/authentication/exceptions.dart';
import 'package:hl_lieferservice/widget/operations/bloc/operation_bloc.dart';
import 'package:hl_lieferservice/widget/operations/bloc/operation_event.dart';
import 'package:rxdart/rxdart.dart';
@ -15,6 +18,7 @@ import 'package:hl_lieferservice/feature/delivery/detail/repository/note_reposit
class NoteBloc extends Bloc<NoteEvent, NoteState> {
final NoteRepository repository;
final OperationBloc opBloc;
final AuthBloc authBloc;
final String deliveryId;
StreamSubscription? _combinedSubscription;
@ -22,6 +26,7 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
NoteBloc({
required this.repository,
required this.opBloc,
required this.authBloc,
required this.deliveryId,
}) : super(NoteInitial()) {
_combinedSubscription = CombineLatestStream.combine3(
@ -60,10 +65,17 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
@override
Future<void> close() {
_combinedSubscription?.cancel();
return super.close();
}
void _handleError(Object e, String fallbackMessage) {
if (e is UserUnauthorized) {
authBloc.add(SessionExpiredEvent());
} else {
opBloc.add(FailOperation(message: fallbackMessage));
}
}
Future<void> _dataUpdated(DataUpdated event, Emitter<NoteState> emit) async {
emit(
NoteLoaded(
@ -82,32 +94,21 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
RemoveImageNote event,
Emitter<NoteState> emit,
) async {
opBloc.add(LoadOperation());
try {
await repository.deleteImage(event.deliveryId, event.objectId);
opBloc.add(FinishOperation());
} catch (e, st) {
debugPrint("Fehler beim Löschen des Bildes: $e");
debugPrint(st.toString());
opBloc.add(FailOperation(message: e.toString()));
debugPrint("Fehler beim Löschen des Bildes: $e $st");
_handleError(e, "Fehler beim Löschen des Bildes");
}
}
Future<void> _upload(AddImageNote event, Emitter<NoteState> emit) async {
opBloc.add(LoadOperation());
try {
Uint8List imageBytes = await event.file.readAsBytes();
await repository.addImage(event.deliveryId, imageBytes);
opBloc.add(FinishOperation());
} catch (e, st) {
debugPrint("Fehler beim Hinzufügen des Bildes: $e");
debugPrint(st.toString());
opBloc.add(FailOperation(message: e.toString()));
debugPrint("Fehler beim Hinzufügen des Bildes: $e $st");
_handleError(e, "Fehler beim Hinzufügen des Bildes");
}
}
@ -117,61 +118,41 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
try {
await repository.loadNotes(event.delivery.id);
await repository.loadTemplates();
opBloc.add(FinishOperation());
} catch (e, st) {
debugPrint("Fehler beim Herunterladen der Notizen: $e");
debugPrint(st.toString());
opBloc.add(
FailOperation(message: "Notizen konnten nicht heruntergeladen werden."),
);
debugPrint("Fehler beim Herunterladen der Notizen: $e $st");
if (e is UserUnauthorized) {
authBloc.add(SessionExpiredEvent());
return;
}
opBloc.add(FailOperation(message: "Notizen konnten nicht heruntergeladen werden."));
emit.call(NoteLoadingFailed());
}
}
Future<void> _add(AddNote event, Emitter<NoteState> emit) async {
opBloc.add(LoadOperation());
try {
await repository.addNote(event.deliveryId, event.note);
opBloc.add(FinishOperation());
} catch (e, st) {
debugPrint("Fehler beim Hinzufügen der Notiz: $e");
debugPrint(st.toString());
opBloc.add(FailOperation(message: e.toString()));
debugPrint("Fehler beim Hinzufügen der Notiz: $e $st");
_handleError(e, "Fehler beim Hinzufügen der Notiz");
}
}
Future<void> _edit(EditNote event, Emitter<NoteState> emit) async {
opBloc.add(LoadOperation());
try {
await repository.editNote(event.noteId, event.content);
opBloc.add(FinishOperation());
} catch (e, st) {
debugPrint("Fehler beim Hinzufügen der Notiz: $e");
debugPrint(st.toString());
opBloc.add(FailOperation(message: e.toString()));
debugPrint("Fehler beim Editieren der Notiz: $e $st");
_handleError(e, "Fehler beim Editieren der Notiz");
}
}
Future<void> _remove(RemoveNote event, Emitter<NoteState> emit) async {
opBloc.add(LoadOperation());
try {
await repository.deleteNote(event.noteId);
opBloc.add(FinishOperation());
} catch (e, st) {
debugPrint("Fehler beim Hinzufügen der Notiz: $e");
debugPrint(st.toString());
opBloc.add(
FailOperation(message: "Notizen konnte nicht gelöscht werden."),
);
debugPrint("Fehler beim Löschen der Notiz: $e $st");
_handleError(e, "Notiz konnte nicht gelöscht werden");
}
}
}

View File

@ -8,6 +8,8 @@ import 'package:url_launcher/url_launcher.dart';
import '../../../bloc/tour_bloc.dart';
import '../../../bloc/tour_state.dart';
enum _StatusAction { hold, cancel, reactivate }
class DeliveryStepInfo extends StatefulWidget {
final Delivery delivery;
@ -39,76 +41,73 @@ class _DeliveryStepInfo extends State<DeliveryStepInfo> {
await launchUrl(url, mode: LaunchMode.externalApplication);
}
Widget _deliveryStatusChangeActions() {
List<Widget> actions = [];
Widget _statusOverflow() {
final state = widget.delivery.state;
final List<PopupMenuEntry<_StatusAction>> entries;
if (widget.delivery.state == DeliveryState.ongoing) {
actions = [
Column(
children: [
IconButton(
onPressed: () {
context.read<TourBloc>().add(
HoldDeliveryEvent(deliveryId: widget.delivery.id),
);
Navigator.of(context).pop();
},
icon: Icon(
Icons.change_circle,
color: Colors.orangeAccent,
size: 42,
),
),
Text("Zurückstellen"),
],
if (state == DeliveryState.ongoing) {
entries = const [
PopupMenuItem(
value: _StatusAction.hold,
child: Row(
children: [
Icon(Icons.change_circle, color: Colors.orangeAccent),
SizedBox(width: 12),
Text("Zurückstellen"),
],
),
),
Column(
children: [
IconButton(
onPressed: () {
context.read<TourBloc>().add(
CancelDeliveryEvent(deliveryId: widget.delivery.id),
);
Navigator.of(context).pop();
},
//style: IconButton.styleFrom(backgroundColor: Colors.red),
icon: Icon(Icons.cancel, color: Colors.red, size: 42),
),
Text("Abbrechen"),
],
PopupMenuItem(
value: _StatusAction.cancel,
child: Row(
children: [
Icon(Icons.cancel, color: Colors.red),
SizedBox(width: 12),
Text("Abbrechen"),
],
),
),
];
} else {
entries = const [
PopupMenuItem(
value: _StatusAction.reactivate,
child: Row(
children: [
Icon(Icons.published_with_changes, color: Colors.blueAccent),
SizedBox(width: 12),
Text("Reaktivieren"),
],
),
),
];
}
if (widget.delivery.state == DeliveryState.canceled ||
widget.delivery.state == DeliveryState.onhold ||
widget.delivery.state == DeliveryState.finished) {
actions = [
Column(
children: [
IconButton(
onPressed: () {
context.read<TourBloc>().add(
ReactivateDeliveryEvent(deliveryId: widget.delivery.id),
);
},
icon: Icon(
Icons.published_with_changes,
color: Colors.blueAccent,
size: 42
),
),
Text("Reaktivieren"),
],
),
];
}
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: actions,
return PopupMenuButton<_StatusAction>(
icon: const Icon(Icons.more_vert),
tooltip: "Status ändern",
itemBuilder: (context) => entries,
onSelected: (action) {
switch (action) {
case _StatusAction.hold:
context.read<TourBloc>().add(
HoldDeliveryEvent(deliveryId: widget.delivery.id),
);
Navigator.of(context).pop();
break;
case _StatusAction.cancel:
context.read<TourBloc>().add(
CancelDeliveryEvent(deliveryId: widget.delivery.id),
);
Navigator.of(context).pop();
break;
case _StatusAction.reactivate:
context.read<TourBloc>().add(
ReactivateDeliveryEvent(deliveryId: widget.delivery.id),
);
break;
}
},
);
}
@ -119,55 +118,46 @@ class _DeliveryStepInfo extends State<DeliveryStepInfo> {
color: Theme.of(context).colorScheme.onSecondary,
child: Padding(
padding: const EdgeInsets.all(10),
child: Column(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Column(
children: [
IconButton.filled(
onPressed:
widget.delivery.contactPerson?.phoneNumber != null
? () async {
Expanded(
child: Builder(
builder: (context) {
final phone = widget.delivery.contactPerson?.phoneNumber;
final bool hasPhone = phone != null && phone.isNotEmpty;
return Column(
mainAxisSize: MainAxisSize.min,
children: [
IconButton.filled(
onPressed: hasPhone
? () async {
await launchUrl(
Uri(
scheme: "tel",
path:
widget
.delivery
.contactPerson
?.phoneNumber!,
),
Uri(scheme: "tel", path: phone),
);
}
: null,
icon: Icon(Icons.phone),
),
Text("Anrufen"),
],
),
Column(
children: [
IconButton.filled(
onPressed: () {
_launchMapsUrl("google");
},
icon: Icon(Icons.map_outlined),
),
Text("Google Maps"),
],
),
],
: null,
icon: const Icon(Icons.phone),
),
const Text("Anrufen"),
],
);
},
),
),
const Padding(
padding: EdgeInsets.only(top: 10, bottom: 10),
child: Divider(),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
IconButton.filled(
onPressed: () => _launchMapsUrl("google"),
icon: const Icon(Icons.map_outlined),
),
const Text("Google Maps"),
],
),
),
_deliveryStatusChangeActions(),
_statusOverflow(),
],
),
),
@ -176,6 +166,16 @@ class _DeliveryStepInfo extends State<DeliveryStepInfo> {
}
Widget _customerInformation() {
final phone = widget.delivery.contactPerson?.phoneNumber;
final String phoneText = (phone != null && phone.isNotEmpty)
? phone
: "keine Nummer angegeben";
final email = widget.delivery.customer.email;
final String emailText = (email != null && email.isNotEmpty)
? email
: "keine E-Mail angegeben";
return SizedBox(
width: double.infinity,
child: Card(
@ -228,9 +228,24 @@ class _DeliveryStepInfo extends State<DeliveryStepInfo> {
Icon(Icons.phone, color: Theme.of(context).primaryColor),
Padding(
padding: const EdgeInsets.only(left: 10),
child: Text(
widget.delivery.contactPerson?.phoneNumber.toString() ??
"",
child: Text(phoneText),
),
],
),
),
Padding(
padding: const EdgeInsets.only(top: 15),
child: Row(
children: [
Icon(Icons.mail, color: Theme.of(context).primaryColor),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: Text(
emailText,
overflow: TextOverflow.ellipsis,
),
),
),
],
@ -275,28 +290,66 @@ class _DeliveryStepInfo extends State<DeliveryStepInfo> {
);
}
Widget _deliveryAgreements() {
Widget _agreementsAndDesiredTime() {
String agreements = "keine Vereinbarungen getroffen!";
if (widget.delivery.specialAgreements != null &&
widget.delivery.specialAgreements != "") {
agreements = widget.delivery.specialAgreements!;
}
final desiredTime = widget.delivery.desiredTime;
final bool hasDesiredTime = desiredTime != null && desiredTime.isNotEmpty;
final primary = Theme.of(context).primaryColor;
return Card(
color: Theme.of(context).colorScheme.onSecondary,
child: Padding(
padding: const EdgeInsets.all(10),
child: Row(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: EdgeInsets.all(15),
child: Icon(
Icons.warning,
color: Theme.of(context).primaryColor,
size: 28,
if (hasDesiredTime) ...[
Row(
children: [
Padding(
padding: const EdgeInsets.all(15),
child: Icon(Icons.schedule, color: primary, size: 28),
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Wunschtermin",
style: TextStyle(
fontSize: 12,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
Text(
desiredTime,
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
color: primary,
),
),
],
),
),
],
),
const Divider(height: 24),
],
Row(
children: [
Padding(
padding: const EdgeInsets.all(15),
child: Icon(Icons.warning, color: primary, size: 28),
),
Expanded(child: Text(agreements)),
],
),
Expanded(child: Text(agreements)),
],
),
),
@ -330,7 +383,7 @@ class _DeliveryStepInfo extends State<DeliveryStepInfo> {
),
Padding(
padding: const EdgeInsets.only(top: 10),
child: _deliveryAgreements(),
child: _agreementsAndDesiredTime(),
),
Padding(

View File

@ -275,10 +275,14 @@ class NoteService {
LocalDocuFrameConfiguration config = getConfig();
return urls.map((url) async {
return (await http.get(
final response = await http.get(
Uri.parse("${config.backendUrl}$url"),
headers: getSessionOrThrow(),
)).bodyBytes;
);
if (response.statusCode == HttpStatus.unauthorized) {
throw UserUnauthorized();
}
return response.bodyBytes;
}).toList();
} catch (e, st) {
debugPrint("An error occured:");