// To parse this JSON data, do // // final welcome = welcomeFromJson(jsonString); import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:pwa_ios/model/json_form_data.dart'; part 'interaction_data.g.dart'; // InteractionResultData welcomeFromJson(String str) => // InteractionResultData.fromJson(json.decode(str)); // String welcomeToJson(InteractionResultData data) => json.encode(data.toJson()); ResponseData ResponseDataFromJson(Map str) => ResponseData.fromJson(str); String ResponseDataToJson(ResponseData data) => json.encode(data.toJson()); class ResponseData { List data; ResponseData({ required this.data, }); factory ResponseData.fromJson(Map json) => ResponseData( data: List.from( json["data"].map((x) => InteractionResultData.fromJson(x))), ); Map toJson() => { "data": List.from(data.map((x) => x.toJson())), }; } @HiveType(typeId: 11) class InteractionResultData { @HiveField(0) List result; @HiveField(1) String id; @HiveField(2) String name; InteractionResultData( {required this.result, required this.id, required this.name}); factory InteractionResultData.fromJson(Map json) => InteractionResultData( result: List.from( json["form-fields"].map((x) => FormFieldData.fromJson(x))), id: json["id"], name: json["name"], ); Map toJson() => { "id": id, "name": name, "result": List.from(result.map((x) => x.toJson())), }; Map saveToJson() => { "save": List.from(result.map((x) => x.saveToJson())), }; } @HiveType(typeId: 4) class FormFieldData { @HiveField(0) String sectionName; @HiveField(1) bool multiple; @HiveField(2) List sectionList; @HiveField(3) List? multipleList; FormFieldData({ required this.sectionName, required this.multiple, required this.sectionList, this.multipleList, }); factory FormFieldData.fromJson(Map json) => FormFieldData( sectionName: json["sectionName"], multiple: json["multiple"], sectionList: List.from( json["sectionList"].map((x) => SectionList.fromJson(x))), ); Map toJson() => { "sectionName": sectionName, "multiple": multiple, "sectionList": List.from(sectionList.map((x) => x.toJson())), }; Map saveToJson() => { "sectionName": sectionName, }; } @HiveType(typeId: 5) class SectionList { @HiveField(0) String name; @HiveField(1) String? param; @HiveField(2) String id; @HiveField(3) int? gid; @HiveField(4) List? selectedValue; @HiveField(5) String? depid; @HiveField(6) InteractionWidget? widget; @HiveField(7) String? input; @HiveField(8) List? inputList; @HiveField(9) bool? isRequired; TextEditingController? controller; @HiveField(10) String? value; @HiveField(11) String? selectedId; @HiveField(12) InputClass? selectedObject; @HiveField(13) Validation? validation; @HiveField(14) String? chars; @HiveField(15) List? extension; @HiveField(16) List? fileName; @HiveField(17) List? tempselectedValue; @HiveField(18) String? max; @HiveField(19) String? min; SectionList( {required this.name, this.param, required this.id, this.selectedValue, this.depid, this.widget, this.input, this.gid, this.inputList, this.isRequired, this.controller, this.selectedObject, this.selectedId, this.validation, this.chars, this.extension, this.fileName, this.tempselectedValue, this.max, this.min, this.value}); factory SectionList.fromJson(Map json) => SectionList( name: json["name"], // param: json["param"], id: json["id"], // selectedValue: List.from(json["selectedValue"].map((x) => x)), depid: json["depid"], widget: widgetValues.map[json["widget"]]!, input: json["input"], inputList: json["inputList"] == null ? [] : List.from( json["inputList"]!.map((x) => InputClass.fromJson(x))), validation: Validation.fromJson(json["validation"]), // chars: json["chars"], max: json["max"], min: json["min"], ); Map toJson() => { "name": name, "param": param, "id": id, "selectedValue": List.from(selectedValue!.map((x) => x)), "depid": depid, "widget": widgetValues.reverse[widget], "input": input, "inputList": inputList == null ? [] : List.from(inputList!.map((x) => x.toJson())), "isRequired": isRequired, "chars": chars, "fileName": List.from(fileName!.map((x) => x)), "extension": List.from(extension!.map((x) => x)), "max": max, "min": min, }; Map saveToJson() => { "name": name, "param": param, "id": id, "selectedValue": List.from(selectedValue!.map((x) => x)), }; } @HiveType(typeId: 6) class InputClass { @HiveField(0) dynamic id; @HiveField(1) String name; @HiveField(2) bool? ischecked; @HiveField(3) String? selectedId; @HiveField(4) String? selectedName; @HiveField(5) List? selectedItems; @HiveField(6) String? pid; InputClass( {required this.id, required this.name, this.ischecked, this.pid, this.selectedId, this.selectedItems, this.selectedName}); factory InputClass.fromJson(Map json) => InputClass( id: json["id"], name: json["name"], pid: json["pid"], ); Map toJson() => {"id": id, "name": name, "pid": pid}; } @HiveType(typeId: 18) class Validation { @HiveField(0) bool isRequired; @HiveField(1) bool? multipleFiles; @HiveField(2) String? type; @HiveField(3) String? chars; Validation({ required this.isRequired, this.multipleFiles, this.type, this.chars, }); factory Validation.fromJson(Map json) => Validation( isRequired: json["isRequired"], multipleFiles: json["multipleFiles"], type: json["type"], chars: json["chars"], ); Map toJson() => { "isRequired": isRequired, "multipleFiles": multipleFiles, "type": type, "chars": chars, }; } @HiveType(typeId: 12) enum InteractionWidget { @HiveField(0) CHECKBOX, @HiveField(1) DROPDOWN, @HiveField(2) LABEL, @HiveField(3) RADIO, @HiveField(4) TEXT, @HiveField(5) BUTTON, @HiveField(6) AUTOCOMPLETE, @HiveField(7) MULTISELECT, @HiveField(8) RANGESLIDER } final widgetValues = EnumValues({ "checkbox": InteractionWidget.CHECKBOX, "dropdown": InteractionWidget.DROPDOWN, "label": InteractionWidget.LABEL, "radio": InteractionWidget.RADIO, "text": InteractionWidget.TEXT, "button": InteractionWidget.BUTTON, "autocomplete": InteractionWidget.AUTOCOMPLETE, "multiselect": InteractionWidget.MULTISELECT, "rangeslider": InteractionWidget.RANGESLIDER }); class EnumValues { Map map; late Map reverseMap; EnumValues(this.map); Map get reverse { reverseMap = map.map((k, v) => MapEntry(v, k)); return reverseMap; } }