From 45c21657ce6921e9fd8f7d23e66c1d798baaea89 Mon Sep 17 00:00:00 2001 From: Sven Carstensen Date: Mon, 29 Jun 2026 12:01:08 +0200 Subject: [PATCH] Neues Aufgaben-JSON verarbeiten: Modell um choices/fields und Listen-Antworten erweitern Co-Authored-By: Claude Opus 4.8 (1M context) --- lib/model/tour_task.dart | 82 +++++++++++++++++++- lib/network_messages/fin_tour_message.dart | 20 +++++ lib/network_messages/fin_tour_message.g.dart | 19 +++++ 3 files changed, 119 insertions(+), 2 deletions(-) diff --git a/lib/model/tour_task.dart b/lib/model/tour_task.dart index 1cf451d..f1aee99 100644 --- a/lib/model/tour_task.dart +++ b/lib/model/tour_task.dart @@ -14,6 +14,12 @@ class TourTask { int? taskFinWork; List? entries; + /// Auswahloptionen eines Status-Tasks (Typ 11). + List? choices; + + /// Eingabefelder einer Text-/Zahlen-Liste (Typ 12/13). + List? fields; + TourTask(); factory TourTask.fromJson(Map json) { @@ -36,6 +42,16 @@ class TourTask { .map((e) => TourEntry.fromJson(e as Map)) .toList() : null; + task.choices = json['choices'] != null + ? (json['choices'] as List) + .map((e) => TourChoice.fromJson(e as Map)) + .toList() + : null; + task.fields = json['fields'] != null + ? (json['fields'] as List) + .map((e) => TourField.fromJson(e as Map)) + .toList() + : null; return task; } @@ -55,6 +71,8 @@ class TourTask { 'task_arrival': taskArrival, 'task_fin_work': taskFinWork, 'entries': entries?.map((e) => e.toJson()).toList(), + 'choices': choices?.map((e) => e.toJson()).toList(), + 'fields': fields?.map((e) => e.toJson()).toList(), }; } } @@ -70,7 +88,7 @@ class TourEntry { final entry = TourEntry(); entry.code = json['code'] as int; entry.text = json['text'] as String; - entry.queryRemark = json['query_remark'] as bool; + entry.queryRemark = json['query_remark'] as bool? ?? false; return entry; } @@ -81,4 +99,64 @@ class TourEntry { 'query_remark': queryRemark, }; } -} \ No newline at end of file +} + +/// Eine Auswahloption eines Status-Tasks (Typ 11). Entspricht {@code Choice} +/// im App-JSON (txt, ret, term, quest, action, price). +class TourChoice { + late String txt; + late int ret; + bool? term; + String? quest; + String? action; + String? price; + + TourChoice(); + + factory TourChoice.fromJson(Map json) { + final choice = TourChoice(); + choice.txt = json['txt'] as String? ?? ''; + choice.ret = json['ret'] as int? ?? 0; + choice.term = json['term'] as bool?; + choice.quest = json['quest'] as String?; + choice.action = json['action'] as String?; + choice.price = json['price'] as String?; + return choice; + } + + Map toJson() { + return { + 'txt': txt, + 'ret': ret, + 'term': term, + 'quest': quest, + 'action': action, + 'price': price, + }; + } + + /// Ob nach Auswahl dieser Option eine zusätzliche Bemerkung erfragt wird. + bool get requiresRemark => (quest != null && quest!.trim().isNotEmpty); +} + +/// Ein Eingabefeld einer Text-/Zahlen-Liste (Typ 12/13). +class TourField { + String? title; + String? placeholder; + + TourField(); + + factory TourField.fromJson(Map json) { + final field = TourField(); + field.title = json['title'] as String?; + field.placeholder = json['placeholder'] as String?; + return field; + } + + Map toJson() { + return { + 'title': title, + 'placeholder': placeholder, + }; + } +} diff --git a/lib/network_messages/fin_tour_message.dart b/lib/network_messages/fin_tour_message.dart index 1ff0e35..c03646c 100644 --- a/lib/network_messages/fin_tour_message.dart +++ b/lib/network_messages/fin_tour_message.dart @@ -49,6 +49,12 @@ class FinTourTask { List? codes; + /// Erfasste Werte einer Text-/Zahlen-Liste (Typ 12/13). + List? fields; + + /// Angekreuzte Codes einer Checkbox-Liste (Typ 14). + List? checked; + FinTaskPos? pos; FinTourTask(); @@ -57,3 +63,17 @@ class FinTourTask { Map toJson() => _$FinTourTaskToJson(this); } + +/// Ein erfasster Wert einer Text-/Zahlen-Liste (Typ 12/13). +@JsonSerializable() +class FinFieldAnswer { + String? title; + + String? val; + + FinFieldAnswer(); + + factory FinFieldAnswer.fromJson(Map json) => _$FinFieldAnswerFromJson(json); + + Map toJson() => _$FinFieldAnswerToJson(this); +} diff --git a/lib/network_messages/fin_tour_message.g.dart b/lib/network_messages/fin_tour_message.g.dart index f881f53..f6c9254 100644 --- a/lib/network_messages/fin_tour_message.g.dart +++ b/lib/network_messages/fin_tour_message.g.dart @@ -39,6 +39,12 @@ FinTourTask _$FinTourTaskFromJson(Map json) => FinTourTask() ..code = (json['code'] as num?)?.toInt() ..sign = json['sign'] as String? ..codes = (json['codes'] as List?)?.map((e) => e as String).toList() + ..fields = (json['fields'] as List?) + ?.map((e) => FinFieldAnswer.fromJson(e as Map)) + .toList() + ..checked = (json['checked'] as List?) + ?.map((e) => (e as num).toInt()) + .toList() ..pos = json['pos'] == null ? null : FinTaskPos.fromJson(json['pos'] as Map); @@ -51,5 +57,18 @@ Map _$FinTourTaskToJson(FinTourTask instance) => 'code': instance.code, 'sign': instance.sign, 'codes': instance.codes, + 'fields': instance.fields, + 'checked': instance.checked, 'pos': instance.pos, }; + +FinFieldAnswer _$FinFieldAnswerFromJson(Map json) => + FinFieldAnswer() + ..title = json['title'] as String? + ..val = json['val'] as String?; + +Map _$FinFieldAnswerToJson(FinFieldAnswer instance) => + { + 'title': instance.title, + 'val': instance.val, + };