diff --git a/lib/feature/delivery/detail/presentation/delivery_options.dart b/lib/feature/delivery/detail/presentation/delivery_options.dart index fcec87e..9807a02 100644 --- a/lib/feature/delivery/detail/presentation/delivery_options.dart +++ b/lib/feature/delivery/detail/presentation/delivery_options.dart @@ -6,7 +6,11 @@ import 'package:hl_lieferservice/model/delivery.dart' as model; import '../../overview/bloc/tour_event.dart'; class DeliveryOptionsView extends StatefulWidget { - const DeliveryOptionsView({super.key, required this.options, required this.deliveryId}); + const DeliveryOptionsView({ + super.key, + required this.options, + required this.deliveryId, + }); final List options; final String deliveryId; @@ -16,9 +20,16 @@ class DeliveryOptionsView extends StatefulWidget { } class _DeliveryOptionsViewState extends State { + late Map _controllers; + @override void initState() { super.initState(); + + _controllers = {}; + for (final option in widget.options.where((option) => option.numerical)) { + _controllers[option.key] = TextEditingController(text: option.getValue().toString()); + } } @override @@ -27,31 +38,33 @@ class _DeliveryOptionsViewState extends State { } void _update(model.DeliveryOption option, dynamic value) { - debugPrint(option.key); - if (value is bool) { context.read().add( - UpdateDeliveryOptionEvent(key: option.key, value: !value, deliveryId: widget.deliveryId), + UpdateDeliveryOptionEvent( + key: option.key, + value: !value, + deliveryId: widget.deliveryId, + ), ); return; } context.read().add( - UpdateDeliveryOptionEvent(key: option.key, value: value, deliveryId: widget.deliveryId), + UpdateDeliveryOptionEvent( + key: option.key, + value: value, + deliveryId: widget.deliveryId, + ), ); } List _options() { List boolOptions = widget.options.where((option) => !option.numerical).map((option) { - debugPrint("Value: ${option.value}, Key: ${option.key}"); - return CheckboxListTile( value: option.getValue(), onChanged: (value) { - debugPrint("HAHAHA"); - debugPrint(value.toString()); _update(option, option.getValue()); }, title: Text(option.display), @@ -64,10 +77,14 @@ class _DeliveryOptionsViewState extends State { padding: const EdgeInsets.all(15), child: TextFormField( decoration: InputDecoration(labelText: option.display), - initialValue: option.getValue().toString(), + controller: _controllers[option.key], keyboardType: TextInputType.number, - onTapOutside: (event) => FocusScope.of(context).unfocus(), - onChanged: (value) { + onTapOutside: (event) { + FocusScope.of(context).unfocus(); + _update(option, _controllers[option.key]?.text); + }, + textInputAction: TextInputAction.done, + onFieldSubmitted: (value) { _update(option, value); }, ), diff --git a/lib/feature/delivery/detail/presentation/delivery_sign.dart b/lib/feature/delivery/detail/presentation/delivery_sign.dart index af335d7..a66556e 100644 --- a/lib/feature/delivery/detail/presentation/delivery_sign.dart +++ b/lib/feature/delivery/detail/presentation/delivery_sign.dart @@ -119,6 +119,8 @@ class _SignatureViewState extends State { builder: (context, state) { final current = state; + debugPrint("STATE: $current"); + if (current is NoteLoaded) { if (current.notes.isEmpty) { return const SizedBox( @@ -209,7 +211,7 @@ class _SignatureViewState extends State { Flexible( child: InkWell( child: Text( - "Ich bestätige, dass ich die Ware im ordnungsgemäßen Zustand erhalten habe und, dass die Aufstell- und Einbauarbeiten korrekt durchgeführt wurden.", + "Ware in ordnungsgemäßem Zustand erhalten. Aufstell- und Einbauarbeiten wurden korrekt durchgeführt", overflow: TextOverflow.fade, ), onTap: () { diff --git a/lib/feature/delivery/detail/presentation/delivery_summary.dart b/lib/feature/delivery/detail/presentation/delivery_summary.dart index 41b3d18..675088f 100644 --- a/lib/feature/delivery/detail/presentation/delivery_summary.dart +++ b/lib/feature/delivery/detail/presentation/delivery_summary.dart @@ -26,7 +26,7 @@ class _DeliverySummaryState extends State { final tourState = context.read().state as TourLoaded; _paymentMethods = [ widget.delivery.payment, - ...tourState.tour.paymentMethods, + ...tourState.paymentOptions, ]; } diff --git a/lib/model/delivery.dart b/lib/model/delivery.dart index aee0917..38a2fa5 100644 --- a/lib/model/delivery.dart +++ b/lib/model/delivery.dart @@ -267,14 +267,17 @@ class Delivery implements Comparable { } Article? findArticleWithNoteId(String noteId) { - Article? filteredArticle = - articles.where((article) => article.removeNoteId == noteId).firstOrNull; - - if (filteredArticle == null && discount?.article != null) { - filteredArticle = discount?.article; + if (discount != null && discount?.noteId == noteId) { + return discount?.article; } - return filteredArticle; + int index = articles.indexWhere((article) => article.removeNoteId == noteId); + // If no article with an according remove note id is found, skip this step. + if (index == -1) { + return null; + } + + return articles[index]; } double getGrossPrice() {