1774 lines
62 KiB
Dart
1774 lines
62 KiB
Dart
// import 'dart:convert';
|
|
// // import 'dart:html';
|
|
|
|
// import 'package:discover_module/ui_screen/interactionform/model/interaction_config_data.dart';
|
|
// import 'package:discover_module/ui_screen/interactionform/model/interaction_data.dart';
|
|
// import 'package:discover_module/ui_screen/interactionform/repository/hive_repository.dart';
|
|
// import 'package:discover_module/ui_screen/interactionform/util.dart';
|
|
// import 'package:flutter/cupertino.dart';
|
|
// import 'package:flutter/material.dart';
|
|
// import 'package:hive_flutter/hive_flutter.dart';
|
|
|
|
// import 'package:discover_module/ui_screen/interactionform/model/json_form_data.dart';
|
|
|
|
// import 'package:discover_module/ui_screen/interactionform/model/location_model.dart';
|
|
|
|
// import 'package:discover_module/ui_screen/interactionform/model/save_interaction.dart';
|
|
|
|
// class InteractionProvider extends ChangeNotifier {
|
|
// List<FormFieldData> interactionReponseList = [];
|
|
// // List<dynamic> sectionList = [];
|
|
// List<SectionList> sectionList = [];
|
|
// late Location locationList;
|
|
// List<TextEditingController> textEditingControllerList = [];
|
|
// List<TextEditingController> multipletextEditingControllerList = [];
|
|
// int textfieldIndex = 0;
|
|
|
|
// List<InputClass> checkboxlist = [];
|
|
|
|
// String radioValue = '';
|
|
// bool checkboxValue = false;
|
|
|
|
// //List<InteractionDatum> data = [];
|
|
// List<SectionList> newList = [];
|
|
// String sectionName = '';
|
|
// late String selectedCity = 'Selected City', selectedState = 'Selected State';
|
|
|
|
// String? selectedValue;
|
|
// List<String> selectedItems = [];
|
|
// InputClass? selectedObj;
|
|
// List<SaveInteraction> savedList = [];
|
|
// List<InteractionConfigData> intConfigDataList = [];
|
|
// String? intId, intName;
|
|
// final HiveDataRepository _hiveprovider = HiveDataRepository(
|
|
// Hive.box<InteractionConfigData>('InteractionConfigDataBox'));
|
|
|
|
// late bool _isLoading;
|
|
|
|
// get isLoading => _isLoading;
|
|
|
|
// initConfigData() async {
|
|
// _hiveprovider.openHiveBox();
|
|
// intConfigDataList = _hiveprovider.getAllDataFromHive();
|
|
// notifyListeners();
|
|
// }
|
|
|
|
// Future<void> getRecords() async {
|
|
// var box = Hive.box<SaveInteraction>('InteractionDataBox');
|
|
|
|
// if (!box.isOpen) {
|
|
// box = await Hive.openBox<SaveInteraction>('InteractionDataBox');
|
|
// }
|
|
|
|
// savedList = box.values.toList();
|
|
// print("savedListt: $savedList");
|
|
// notifyListeners();
|
|
// }
|
|
|
|
// init(int index) async {
|
|
// await initConfigData();
|
|
// InteractionConfigData interactionConfigData = intConfigDataList[index];
|
|
// intId = intConfigDataList[index].id;
|
|
// intName = intConfigDataList[index].name;
|
|
|
|
// radioValue = '';
|
|
// print("data $intConfigDataList");
|
|
|
|
// await fetchData(interactionConfigData.widgets);
|
|
// notifyListeners();
|
|
// }
|
|
|
|
// initSavedForm(SaveInteraction saveInteractiondata) {
|
|
// interactionReponseList = saveInteractiondata.save
|
|
// .map((e) => FormFieldData(
|
|
// multipleList: e.multipleList == null
|
|
// ? []
|
|
// : e.multipleList!
|
|
// .map((mobj) => SectionList(
|
|
// depid: mobj.depid,
|
|
// id: mobj.id,
|
|
// inputList: mobj.inputList,
|
|
// isRequired: mobj.isRequired,
|
|
// name: mobj.name,
|
|
// param: mobj.param,
|
|
// selectedValue: mobj.selectedValue,
|
|
// fileName: mobj.fileName,
|
|
// extension: mobj.extension,
|
|
// widget: mobj.widget,
|
|
// controller: mobj.controller,
|
|
// gid: mobj.gid,
|
|
// input: mobj.input,
|
|
// selectedId: mobj.selectedId,
|
|
// value: mobj.value))
|
|
// .toList(),
|
|
// sectionList: e.sectionList
|
|
// .map((obj) => SectionList(
|
|
// depid: obj.depid,
|
|
// id: obj.id,
|
|
// inputList: obj.inputList,
|
|
// isRequired: obj.isRequired,
|
|
// name: obj.name,
|
|
// param: obj.param,
|
|
// fileName: obj.fileName,
|
|
// extension: obj.extension,
|
|
// selectedValue: obj.selectedValue,
|
|
// widget: obj.widget,
|
|
// controller: obj.controller,
|
|
// gid: obj.gid,
|
|
// input: obj.input,
|
|
// selectedId: obj.selectedId,
|
|
// value: obj.value,
|
|
// ))
|
|
// .toList(),
|
|
// sectionName: e.sectionName,
|
|
// multiple: e.multiple))
|
|
// .toList();
|
|
|
|
// textEditingControllerList.clear();
|
|
|
|
// for (var item in interactionReponseList) {
|
|
// sectionList = item.sectionList;
|
|
// for (var sectionItem in item.sectionList) {
|
|
// if (sectionItem.widget == InteractionWidget.TEXT) {
|
|
// var textEditingController = TextEditingController();
|
|
|
|
// textEditingControllerList.add(textEditingController);
|
|
// sectionItem.controller = textEditingControllerList.last;
|
|
// }
|
|
// if (sectionItem.widget == InteractionWidget.DROPDOWN ||
|
|
// sectionItem.widget == InteractionWidget.AUTOCOMPLETE ||
|
|
// sectionItem.widget == InteractionWidget.MULTISELECT) {
|
|
// List<InputClass> list = sectionItem.inputList!;
|
|
// sectionItem.value = list[0].id;
|
|
// print("value : ${list.first} ");
|
|
// }
|
|
// }
|
|
// }
|
|
// print(interactionReponseList);
|
|
// print("check textcontrollers ${textEditingControllerList.length}");
|
|
// }
|
|
|
|
// String getDataValue(String widgetId, String id) {
|
|
// print("issue *************");
|
|
// if (id != "") {
|
|
// List<InputClass> list = [];
|
|
// String value = ' ';
|
|
|
|
// for (FormFieldData obj1 in interactionReponseList) {
|
|
// // List<InputClass> list =
|
|
// for (SectionList obj in obj1.sectionList) {
|
|
// if (obj.id == widgetId) {
|
|
// list = obj.inputList!;
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// if (list.isNotEmpty) {
|
|
// int index = list.indexWhere((element) => element.id.toString() == id);
|
|
|
|
// if (index != -1) {
|
|
// value = list[index].name;
|
|
// }
|
|
// }
|
|
|
|
// return value;
|
|
// } else {
|
|
// return " ";
|
|
// }
|
|
// }
|
|
|
|
// // TODO: Search for widget with depid and check if selected is not null and by selected id get the data of current widget
|
|
|
|
// List<InputClass> getData2(SectionList sectionItem) {
|
|
// print("SEctionItemmmmm: $selectedValue");
|
|
// List<InputClass> list = [];
|
|
// // if (sectionItem.inputList != null) {
|
|
// list = sectionItem.inputList!;
|
|
// if (sectionItem.depid != "") {
|
|
// // print("check depid : ${sectionItem.depid}");
|
|
// int i = 0;
|
|
// for (var obj in interactionReponseList) {
|
|
// i = obj.sectionList
|
|
// .indexWhere((element) => element.id == sectionItem.depid);
|
|
// // print("check depid index: $i");
|
|
// if (i != -1) {
|
|
// //print("check depid value: ${obj.sectionList[i].value}");
|
|
// if (obj.sectionList[i].value != null) {
|
|
// if (list
|
|
// .where((element) => element.pid == obj.sectionList[i].value)
|
|
// .isNotEmpty) {
|
|
// list = list
|
|
// .where((element) => element.pid == obj.sectionList[i].value)
|
|
// .toList();
|
|
|
|
// sectionItem.selectedObject = list[0];
|
|
// } else {
|
|
// // InputClass obj = InputClass(
|
|
// // id: "obj.sectionList[i].value",
|
|
// // name: "Select ${sectionItem.name}");
|
|
// list = [];
|
|
// // list.add(obj);
|
|
// sectionItem.selectedObject = null;
|
|
// }
|
|
// } else {
|
|
// // int index = obj.sectionList
|
|
// // .indexWhere((element) => element.id == sectionItem.id);
|
|
|
|
// // list = obj.sectionList[index].inputList;
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// // int index = data[i].data.indexWhere((element) => element.)
|
|
// }
|
|
// // }
|
|
// return list;
|
|
// }
|
|
|
|
// setDropDownValue(String value, SectionList sectionItem, bool multiple) {
|
|
// int i = 0;
|
|
// print("selected $value");
|
|
// for (var obj in interactionReponseList) {
|
|
// if (multiple && obj.multipleList != null) {
|
|
// i = obj.multipleList!
|
|
// .indexWhere((element) => element.id == sectionItem.id);
|
|
// if (i != -1) {
|
|
// obj.multipleList![i].value = value;
|
|
// obj.multipleList![i].selectedValue!.add(value);
|
|
// }
|
|
// } else {
|
|
// i = obj.sectionList
|
|
// .indexWhere((element) => element.id == sectionItem.id);
|
|
// if (i != -1) {
|
|
// obj.sectionList[i].value = value;
|
|
// obj.sectionList[i].selectedValue!.add(value);
|
|
// }
|
|
// }
|
|
// }
|
|
// notifyListeners();
|
|
// }
|
|
|
|
// // setTextValue(String value, SectionList sectionItem, bool multiple) {
|
|
// // print("Text_val = $value, $sectionItem, $multiple");
|
|
// // int i = 0;
|
|
// // for (var obj in interactionReponseList) {
|
|
// // if (multiple && obj.multipleList != null) {
|
|
// // i = obj.multipleList!
|
|
// // .indexWhere((element) => element.id == sectionItem.id);
|
|
// // if (i != -1) {
|
|
// // obj.multipleList![i].value = value;
|
|
// // obj.multipleList![i].selectedValue!.add(value);
|
|
// // }
|
|
// // } else {
|
|
// // i = obj.sectionList
|
|
// // .indexWhere((element) => element.id == sectionItem.id);
|
|
// // if (i != -1) {
|
|
// // obj.sectionList[i].value = value;
|
|
// // obj.sectionList[i].selectedValue!.add(value);
|
|
// // }
|
|
// // }
|
|
// // }
|
|
// // notifyListeners();
|
|
// // }
|
|
|
|
// setTextValue(String value, SectionList sectionItem, bool multiple) {
|
|
// int i = 0;
|
|
// for (var obj in interactionReponseList) {
|
|
// if (multiple && obj.multipleList != null) {
|
|
// i = obj.multipleList!.indexWhere((element) =>
|
|
// element.id == sectionItem.id && element.gid == sectionItem.gid);
|
|
// if (i != -1) {
|
|
// obj.multipleList![i].value = value;
|
|
// obj.multipleList![i].selectedValue!.add(value);
|
|
// }
|
|
// } else {
|
|
// i = obj.sectionList
|
|
// .indexWhere((element) => element.id == sectionItem.id);
|
|
// if (i != -1) {
|
|
// obj.sectionList[i].value = value;
|
|
// obj.sectionList[i].selectedValue!.add(value);
|
|
// }
|
|
// }
|
|
// }
|
|
// notifyListeners();
|
|
// }
|
|
|
|
// setAutoCompleteValue(String value, SectionList sectionItem, bool multiple) {
|
|
// int i = 0;
|
|
// for (var obj in interactionReponseList) {
|
|
// if (multiple && obj.multipleList != null) {
|
|
// i = obj.multipleList!
|
|
// .indexWhere((element) => element.id == sectionItem.id);
|
|
// if (i != -1) {
|
|
// obj.multipleList![i].value = value;
|
|
// obj.multipleList![i].selectedValue!.add(value);
|
|
// }
|
|
// } else {
|
|
// i = obj.sectionList
|
|
// .indexWhere((element) => element.id == sectionItem.id);
|
|
// if (i != -1) {
|
|
// obj.sectionList[i].value = value;
|
|
// obj.sectionList[i].selectedValue!.add(value);
|
|
// }
|
|
// }
|
|
// }
|
|
// notifyListeners();
|
|
// }
|
|
|
|
// Future<String> fetchData(InteractionResultData interactionResultData) async {
|
|
// InteractionResultData interactionConfig = interactionResultData;
|
|
|
|
// print("itemCategoryModel Item = + ${interactionConfig.result}");
|
|
// // }
|
|
// interactionReponseList = interactionConfig.result;
|
|
// print("check stored: $interactionReponseList");
|
|
|
|
// textEditingControllerList.clear();
|
|
|
|
// for (var item in interactionReponseList) {
|
|
// sectionList = item.sectionList;
|
|
// for (var sectionItem in item.sectionList) {
|
|
// sectionItem.selectedValue = [];
|
|
// if (sectionItem.widget == InteractionWidget.TEXT) {
|
|
// var textEditingController = TextEditingController();
|
|
|
|
// textEditingControllerList.add(textEditingController);
|
|
// sectionItem.controller = textEditingControllerList.last;
|
|
// }
|
|
// if (sectionItem.widget == InteractionWidget.DROPDOWN ||
|
|
// sectionItem.widget == InteractionWidget.AUTOCOMPLETE ||
|
|
// sectionItem.widget == InteractionWidget.MULTISELECT) {
|
|
// // int index = data
|
|
// // .indexWhere((element) => element.widgetId == sectionItem.id);
|
|
// // List<InputClass> list = data[index].data;
|
|
// List<InputClass> list = sectionItem.inputList!;
|
|
// sectionItem.value = list[0].id;
|
|
// if (sectionItem.widget == InteractionWidget.MULTISELECT) {
|
|
// sectionItem.selectedValue!.add(list[0].name);
|
|
// } else {
|
|
// sectionItem.selectedValue!.add(list[0].id);
|
|
// }
|
|
|
|
// sectionItem.selectedObject = list[0];
|
|
// print("value : ${list.first} ");
|
|
// } else if (sectionItem.widget == InteractionWidget.CHECKBOX) {
|
|
// List<InputClass> list = sectionItem.inputList!;
|
|
// if (list.isNotEmpty) {
|
|
// for (var element in sectionItem.inputList!) {
|
|
// element.ischecked = false;
|
|
// }
|
|
// }
|
|
// // sectionItem.value = list[0].id;
|
|
// // sectionItem.selectedValue!.add(list[0].id);
|
|
// }
|
|
// }
|
|
// }
|
|
// print(interactionReponseList);
|
|
// print("check textcontrollers ${textEditingControllerList.length}");
|
|
// notifyListeners();
|
|
|
|
// return "success";
|
|
// }
|
|
|
|
// resetAllWidgetsData() {
|
|
// textEditingControllerList.clear();
|
|
|
|
// for (var item in interactionReponseList) {
|
|
// item.multipleList = [];
|
|
// sectionList = item.sectionList;
|
|
// for (var sectionItem in item.sectionList) {
|
|
// sectionItem.selectedValue = [];
|
|
// // sectionItem.value = '';
|
|
// // sectionItem.selectedObject = InputClass(id: '', name: '');
|
|
// if (sectionItem.widget == InteractionWidget.TEXT) {
|
|
// var textEditingController = TextEditingController();
|
|
|
|
// textEditingControllerList.add(textEditingController);
|
|
// sectionItem.controller = textEditingControllerList.last;
|
|
// }
|
|
// if (item.sectionName != "Other") {
|
|
// if (sectionItem.widget == InteractionWidget.DROPDOWN ||
|
|
// sectionItem.widget == InteractionWidget.AUTOCOMPLETE ||
|
|
// sectionItem.widget == InteractionWidget.MULTISELECT) {
|
|
// // int index = data
|
|
// // .indexWhere((element) => element.widgetId == sectionItem.id);
|
|
// print("Selected widget : ${sectionItem.id}");
|
|
// List<InputClass> list = sectionItem.inputList!;
|
|
// sectionItem.value = list[0].id;
|
|
// sectionItem.selectedObject = list[0];
|
|
// print("value : ${list.first.name} ");
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// print(interactionReponseList);
|
|
// print("check textcontrollers ${textEditingControllerList.length}");
|
|
// notifyListeners();
|
|
// }
|
|
|
|
// setRadioValue(SectionList sectionItem) {
|
|
// List<InputClass> list = (sectionItem.input as List)
|
|
// .map((itemWord) => InputClass.fromJson(itemWord))
|
|
// .toList();
|
|
// radioValue = list[0].name;
|
|
|
|
// notifyListeners();
|
|
// }
|
|
|
|
// setcheckBoxValue(SectionList sectionItem, String sectionName, bool newValue,
|
|
// String id, bool multiple) {
|
|
// int index =
|
|
// sectionItem.inputList!.indexWhere((element) => element.id == id);
|
|
// sectionItem.inputList![index].ischecked = newValue;
|
|
// // sectionItem.selectedValue.add(data[i].data[index].id);
|
|
// int index2 = 0;
|
|
// for (var obj in interactionReponseList) {
|
|
// if (multiple && obj.multipleList != null) {
|
|
// index2 = obj.multipleList!
|
|
// .indexWhere((element) => element.id == sectionItem.id);
|
|
// if (index2 != -1) {
|
|
// obj.multipleList![index2].value = sectionItem.inputList![index].id;
|
|
// obj.multipleList![index2].selectedValue!
|
|
// .add(sectionItem.inputList![index].id);
|
|
// }
|
|
// } else {
|
|
// index2 = obj.sectionList
|
|
// .indexWhere((element) => element.id == sectionItem.id);
|
|
// if (index2 != -1) {
|
|
// obj.sectionList[index2].value = sectionItem.inputList![index].id;
|
|
// obj.sectionList[index2].selectedValue!
|
|
// .add(sectionItem.inputList![index].id);
|
|
// }
|
|
// }
|
|
// }
|
|
// notifyListeners();
|
|
// }
|
|
|
|
// // getSectionItem(String sectionName) {
|
|
// // print("sectionName_issss : $sectionName");
|
|
// // newList = [];
|
|
// // List<SectionList> addList = [];
|
|
// // int index = interactionReponseList
|
|
// // .indexWhere((element) => element.sectionName == sectionName);
|
|
|
|
// // print("addList_isss: $addList");
|
|
|
|
// // addList = interactionReponseList[index]
|
|
// // .sectionList
|
|
// // .map((e) => SectionList(
|
|
// // depid: e.depid,
|
|
// // id: e.id,
|
|
// // inputList: e.inputList,
|
|
// // isRequired: e.isRequired,
|
|
// // name: e.name,
|
|
// // param: e.param,
|
|
// // selectedValue: [],
|
|
// // widget: e.widget,
|
|
// // controller: e.controller,
|
|
// // gid: e.gid,
|
|
// // input: e.input,
|
|
// // selectedId: e.selectedId,
|
|
// // value: e.value))
|
|
// // .toList();
|
|
// // SectionList delItem = SectionList(
|
|
// // name: "delete",
|
|
// // param: "deletebtn",
|
|
// // id: "deletebtn",
|
|
// // selectedValue: [],
|
|
// // depid: "",
|
|
// // widget: InteractionWidget.BUTTON,
|
|
// // inputList: [],
|
|
// // isRequired: true);
|
|
|
|
// // addList.add(delItem);
|
|
|
|
// // // if (interactionReponseList[index].multipleList!.isEmpty) {
|
|
// // // newList = addList;
|
|
// // // } else {
|
|
// // if (interactionReponseList[index].multipleList == null) {
|
|
// // interactionReponseList[index].multipleList = addList;
|
|
// // print("iff: $addList");
|
|
// // } else {
|
|
// // // interactionReponseList[index].multipleList =
|
|
// // // // interactionReponseList[index].multipleList! + addList;
|
|
// // // interactionReponseList[index].multipleList! + addList;
|
|
|
|
// // interactionReponseList[index].multipleList =
|
|
// // interactionReponseList[index].multipleList! + addList;
|
|
|
|
// // print("iffelse: $addList");
|
|
// // }
|
|
|
|
// // newList = interactionReponseList[index].multipleList!;
|
|
|
|
// // print("newList_iss: $newList");
|
|
|
|
// // // newList = newList + addList;
|
|
// // // }
|
|
// // if (interactionReponseList[index].multipleList != null) {
|
|
// // for (SectionList obj in interactionReponseList[index].multipleList!) {
|
|
// // obj.gid = obj.gid ?? interactionReponseList[index].multipleList!.length;
|
|
// // if (obj.widget == InteractionWidget.TEXT) {
|
|
// // print("objectt");
|
|
// // var textEditingController = TextEditingController();
|
|
|
|
// // multipletextEditingControllerList.add(textEditingController);
|
|
// // obj.controller = multipletextEditingControllerList.last;
|
|
// // }
|
|
// // // newList.add(obj);
|
|
// // }
|
|
// // }
|
|
|
|
// // print(
|
|
// // "check length : ${interactionReponseList[index].multipleList!.length}");
|
|
// // notifyListeners();
|
|
// // }
|
|
|
|
// getSectionItem(String sectionName) {
|
|
// newList = [];
|
|
// List<SectionList> addList = [];
|
|
// int index = interactionReponseList
|
|
// .indexWhere((element) => element.sectionName == sectionName);
|
|
// var textEditingController = TextEditingController();
|
|
// addList = interactionReponseList[index]
|
|
// .sectionList
|
|
// .map((e) => SectionList(
|
|
// depid: e.depid,
|
|
// id: e.id,
|
|
// inputList: e.inputList,
|
|
// isRequired: e.isRequired,
|
|
// name: e.name,
|
|
// param: e.param,
|
|
// selectedValue: [],
|
|
// widget: e.widget,
|
|
// controller: e.controller,
|
|
// gid: e.gid,
|
|
// input: e.input,
|
|
// selectedId: e.selectedId,
|
|
// value: e.value))
|
|
// .toList();
|
|
// SectionList delItem = SectionList(
|
|
// name: "delete",
|
|
// param: "deletebtn",
|
|
// id: "deletebtn",
|
|
// selectedValue: [],
|
|
// depid: "",
|
|
// widget: InteractionWidget.BUTTON,
|
|
// inputList: [],
|
|
// isRequired: true);
|
|
|
|
// addList.add(delItem);
|
|
|
|
// for (SectionList obj in addList) {
|
|
// //obj.gid = obj.gid ?? addList.length;
|
|
// if (obj.widget == InteractionWidget.TEXT) {
|
|
// var textEditingController = TextEditingController();
|
|
|
|
// multipletextEditingControllerList.add(textEditingController);
|
|
// obj.controller = multipletextEditingControllerList.last;
|
|
// }
|
|
// // newList.add(obj);
|
|
// }
|
|
|
|
// // if (interactionReponseList[index].multipleList!.isEmpty) {
|
|
// // newList = addList;
|
|
// // } else {
|
|
// if (interactionReponseList[index].multipleList == null) {
|
|
// interactionReponseList[index].multipleList = addList;
|
|
// } else {
|
|
// interactionReponseList[index].multipleList =
|
|
// interactionReponseList[index].multipleList! + addList;
|
|
// }
|
|
|
|
// newList = interactionReponseList[index].multipleList!;
|
|
// // newList = newList + addList;
|
|
// // }
|
|
// if (interactionReponseList[index].multipleList != null) {
|
|
// for (SectionList obj in interactionReponseList[index].multipleList!) {
|
|
// obj.gid = obj.gid ?? interactionReponseList[index].multipleList!.length;
|
|
// // if (obj.widget == InteractionWidget.TEXT) {
|
|
// // var textEditingController = TextEditingController();
|
|
|
|
// // multipletextEditingControllerList.add(textEditingController);
|
|
// // obj.controller = multipletextEditingControllerList.last;
|
|
// // }
|
|
// //newList.add(obj);
|
|
// }
|
|
// }
|
|
|
|
// print(
|
|
// "check length : ${interactionReponseList[index].multipleList!.length}");
|
|
// notifyListeners();
|
|
// }
|
|
|
|
// deleteMultipleRows(
|
|
// int gid, SectionList sectionItem, String selectedSectionName) {
|
|
// int index = interactionReponseList
|
|
// .indexWhere((element) => element.sectionName == selectedSectionName);
|
|
|
|
// print("controllerssssss : ${multipletextEditingControllerList.length}");
|
|
// interactionReponseList[index]
|
|
// .multipleList!
|
|
// .removeWhere((item) => item.gid == gid);
|
|
|
|
// notifyListeners();
|
|
// }
|
|
|
|
// bool validateMultipleRows() {
|
|
// for (var obj in interactionReponseList) {
|
|
// if (obj.multipleList != null) {
|
|
// for (var mulobj in obj.multipleList!) {
|
|
// if (mulobj.widget == InteractionWidget.TEXT) {
|
|
// if (mulobj.controller!.text.isEmpty) {
|
|
// return true;
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// return false;
|
|
// }
|
|
|
|
// // bool validateTextFields() {
|
|
// // for (var obj in interactionReponseList) {
|
|
// // print("validateForm_is: ${obj.sectionList}");
|
|
// // for (var mulobj in obj.sectionList) {
|
|
// // print("mulobj_is: ${mulobj}");
|
|
// // print("mulobj_is: ${mulobj.widget}");
|
|
// // print("mulobj_is: ${mulobj.isRequired}");
|
|
|
|
// // if (mulobj.widget == InteractionWidget.TEXT) {
|
|
// // if (mulobj.controller!.text.isEmpty) {
|
|
// // return true;
|
|
// // }
|
|
// // }
|
|
// // }
|
|
// // }
|
|
// // return false;
|
|
// // }
|
|
|
|
// bool validateTextFields() {
|
|
// print("Validation_is : ${interactionReponseList.isEmpty}");
|
|
// for (var obj in interactionReponseList) {
|
|
// print("validateForm_is: ${obj.sectionList}");
|
|
// for (var mulobj in obj.sectionList) {
|
|
// print("mulobj_is: ${mulobj}");
|
|
// print("mulobj_is: ${mulobj.widget}");
|
|
// print("mulobj_is: ${mulobj.validation!.isRequired}");
|
|
|
|
// // if (mulobj.widget == InteractionWidget.TEXT) {
|
|
// // if (mulobj.controller!.text.isEmpty) {
|
|
// // print("I_amTextWidget");
|
|
// // return false;
|
|
// // }
|
|
// // }
|
|
|
|
// if (mulobj.validation!.isRequired == true) {
|
|
// if (mulobj.widget == InteractionWidget.TEXT) {
|
|
// if (mulobj.controller!.text.isEmpty) {
|
|
// print("Text_isEmpty");
|
|
// //return false;
|
|
// }
|
|
// } else if (mulobj.widget == InteractionWidget.AUTOCOMPLETE) {
|
|
// if (mulobj.selectedId == null) {
|
|
// print("Auto_isEmpty");
|
|
// //return false;
|
|
// }
|
|
// } else if (mulobj.widget == InteractionWidget.DROPDOWN) {
|
|
// if (mulobj.selectedId == null) {
|
|
// print("Dropdown_isEmpty");
|
|
// //return false;
|
|
// }
|
|
// } else if (mulobj.widget == InteractionWidget.values) {
|
|
// if (mulobj.selectedId == null) {
|
|
// print("Dropdown_isEmpty");
|
|
// //return false;
|
|
// }
|
|
// }
|
|
// // showDialog(context: context, builder: (_){
|
|
|
|
// // return AboutDialog()
|
|
// // });
|
|
// }
|
|
// }
|
|
// return false;
|
|
// }
|
|
// return false;
|
|
// }
|
|
|
|
// Future<String> saveJsonObject(BuildContext context, String form,
|
|
// {bool isEdit = false}) async {
|
|
// print("form_data: $form");
|
|
// List<FormFieldData> resultData = interactionReponseList
|
|
// .map((e) => FormFieldData(
|
|
// multipleList: e.multipleList == null
|
|
// ? []
|
|
// : e.multipleList!
|
|
// .map((mobj) => SectionList(
|
|
// depid: mobj.depid,
|
|
// id: mobj.id,
|
|
// inputList: mobj.inputList,
|
|
// isRequired: mobj.isRequired,
|
|
// name: mobj.name,
|
|
// param: mobj.param,
|
|
// selectedValue: mobj.selectedValue,
|
|
// extension: mobj.extension,
|
|
// fileName: mobj.fileName,
|
|
// widget: mobj.widget,
|
|
// // controller: mobj.controller,
|
|
// gid: mobj.gid,
|
|
// input: mobj.input,
|
|
// selectedId: mobj.selectedId,
|
|
// value: mobj.value))
|
|
// .toList(),
|
|
// sectionList: e.sectionList
|
|
// .map((obj) => SectionList(
|
|
// depid: obj.depid,
|
|
// id: obj.id,
|
|
// inputList: obj.inputList,
|
|
// isRequired: obj.isRequired,
|
|
// name: obj.name,
|
|
// param: obj.param,
|
|
// selectedValue: obj.selectedValue,
|
|
// widget: obj.widget,
|
|
// controller: obj.controller,
|
|
// gid: obj.gid,
|
|
// input: obj.input,
|
|
// extension: obj.extension,
|
|
// fileName: obj.fileName,
|
|
// selectedId: obj.selectedId,
|
|
// value: obj.value))
|
|
// .toList(),
|
|
// sectionName: e.sectionName,
|
|
// multiple: e.multiple))
|
|
// .toList();
|
|
|
|
// String generateId = '${intId}R${await getNextAutoIncrementValue()}';
|
|
|
|
// print("Result_data_is: ${FormFieldData}");
|
|
|
|
// if (validateSectionList(resultData)) {
|
|
// _isLoading = true;
|
|
// notifyListeners();
|
|
// final data = SaveInteraction(
|
|
// save: resultData,
|
|
// id: generateId,
|
|
// updatedTime: DateTime.now().toString(),
|
|
// form: form,
|
|
// intId: intId ?? "id",
|
|
// intName: intName ?? "name");
|
|
// var box = Hive.box<SaveInteraction>('InteractionDataBox');
|
|
|
|
// if (!box.isOpen) {
|
|
// box = await Hive.openBox<SaveInteraction>('InteractionDataBox');
|
|
// }
|
|
|
|
// print("Data_Result_is: ${data}");
|
|
|
|
// // // if (validateJson1(data.save.first)) {
|
|
// await box.put(await getNextAutoIncrementValue(), data);
|
|
// } else {
|
|
// _isLoading = false;
|
|
// notifyListeners();
|
|
|
|
// // Handle validation error
|
|
// print("JSON data is not valid according to the schema.");
|
|
// }
|
|
// // box.close();
|
|
// await getRecords();
|
|
// return generateId;
|
|
// }
|
|
|
|
// List<MultipleSectionList> getModifiedList(List<SectionList> sectionList) {
|
|
// List<MultipleSectionList> newSectionList = [];
|
|
// for (var obj in sectionList) {
|
|
// if (obj.id != 'deletebtn') {
|
|
// if (obj.input == 'chooseFile') {
|
|
// MultipleSectionList newobj = MultipleSectionList(
|
|
// id: obj.id,
|
|
// selectedValue: obj.selectedValue!,
|
|
// extension: obj.extension!,
|
|
// fileName: obj.fileName!,
|
|
// );
|
|
|
|
// newSectionList.add(newobj);
|
|
// } else {
|
|
// MultipleSectionList newobj = MultipleSectionList(
|
|
// id: obj.id,
|
|
// selectedValue: obj.selectedValue!,
|
|
// );
|
|
// newSectionList.add(newobj);
|
|
// }
|
|
// }
|
|
// }
|
|
// return newSectionList;
|
|
// }
|
|
|
|
// List<List<MultipleSectionList>> getMultipleSectionList(
|
|
// List<SectionList> sectionList, List<SectionList> multipleList) {
|
|
// List<List<MultipleSectionList>> list = [];
|
|
// List<List<MultipleSectionList>> listing = [];
|
|
// List<MultipleSectionList> secList = getModifiedList(sectionList);
|
|
// List<MultipleSectionList> multipleList0 = getModifiedList(multipleList);
|
|
// list.add(secList);
|
|
// listing.add(secList);
|
|
// // List<SectionList> listing = [];
|
|
// if (multipleList.isNotEmpty) {
|
|
// final releaseDateMap = multipleList.groupBy((m) => m.gid);
|
|
// print("see map : $releaseDateMap");
|
|
|
|
// if (releaseDateMap.isNotEmpty) {
|
|
// listing = [];
|
|
// List<List<SectionList>> mulList =
|
|
// releaseDateMap.values.toList(growable: true);
|
|
// for (var item in mulList) {
|
|
// listing.add(getModifiedList(item));
|
|
// }
|
|
// listing.add(secList);
|
|
// list = [...listing];
|
|
|
|
// //});
|
|
// }
|
|
// }
|
|
// return list;
|
|
// }
|
|
|
|
// SaveInteractionFormJson formJson(SaveInteraction saveInteraction) {
|
|
// List<Save> saveList = [];
|
|
// for (var obj in saveInteraction.save) {
|
|
// Save saveobj = Save(
|
|
// sectionName: obj.sectionName,
|
|
// multipleSectionList:
|
|
// getMultipleSectionList(obj.sectionList, obj.multipleList!));
|
|
// saveList.add(saveobj);
|
|
// }
|
|
|
|
// SaveInteractionFormJson saveInteractionFormJson = SaveInteractionFormJson(
|
|
// interactionForm1: saveInteraction.form!,
|
|
// intId: saveInteraction.id,
|
|
// intName: saveInteraction.intName,
|
|
// save: saveList);
|
|
// return saveInteractionFormJson;
|
|
// }
|
|
|
|
// bool validateJson1(FormFieldData data) {
|
|
// print("Checking_data1 ${data.sectionName}");
|
|
|
|
// print("Checking_data1 ${data.sectionList}");
|
|
// return false;
|
|
// }
|
|
|
|
// bool validateSectionList(List<FormFieldData> resultData) {
|
|
// for (var formData in resultData) {
|
|
// for (var section in formData.sectionList) {
|
|
// print("Section_isssss: $section");
|
|
// print("Section_isssss: ${section.isRequired}");
|
|
// print("Section_isssss: ${section.widget}");
|
|
|
|
// if (section.widget == InteractionWidget.TEXT) {
|
|
// if (section.controller!.text.isEmpty) {
|
|
// debugPrint("Iam text and empty");
|
|
// notifyListeners();
|
|
|
|
// return false;
|
|
// }
|
|
// } else if (section.widget == InteractionWidget.AUTOCOMPLETE) {
|
|
// if (section.selectedValue!.isEmpty) {
|
|
// debugPrint("Iam AUTOCOMPLETE and empty");
|
|
// notifyListeners();
|
|
|
|
// return false;
|
|
// }
|
|
// } else if (section.widget == InteractionWidget.DROPDOWN) {
|
|
// if (section.selectedValue!.isEmpty) {
|
|
// debugPrint("Iam dropdown and empty");
|
|
// notifyListeners();
|
|
|
|
// return false;
|
|
// }
|
|
// } else if (section.widget == InteractionWidget.CHECKBOX) {
|
|
// if (section.selectedValue!.isEmpty) {
|
|
// debugPrint("Iam CHECKBOX and empty");
|
|
// notifyListeners();
|
|
|
|
// return false;
|
|
// }
|
|
// }
|
|
// }
|
|
// // print("Multilist");
|
|
// // for (var msection in formData.multipleList!) {
|
|
// // print("Multilist Enter");
|
|
|
|
// // print("Multilist Enterwidget: ${msection.widget}");
|
|
|
|
// // if (msection.widget == InteractionWidget.TEXT) {
|
|
// // if (msection.controller!.text.isEmpty) {
|
|
// // debugPrint("Iam text and empty");
|
|
// // notifyListeners();
|
|
|
|
// // return false;
|
|
// // }
|
|
// // } else if (msection.widget == InteractionWidget.AUTOCOMPLETE) {
|
|
// // if (msection.selectedValue!.isEmpty) {
|
|
// // debugPrint("Iam AUTOCOMPLETE and empty");
|
|
// // notifyListeners();
|
|
|
|
// // return false;
|
|
// // }
|
|
// // } else if (msection.widget == InteractionWidget.DROPDOWN) {
|
|
// // if (msection.selectedValue!.isEmpty) {
|
|
// // debugPrint("Iam dropdown and empty");
|
|
// // notifyListeners();
|
|
|
|
// // return false;
|
|
// // }
|
|
// // } else if (msection.widget == InteractionWidget.CHECKBOX) {
|
|
// // if (msection.selectedValue!.isEmpty) {
|
|
// // debugPrint("Iam CHECKBOX and empty");
|
|
// // notifyListeners();
|
|
|
|
// // return false;
|
|
// // }
|
|
// // }
|
|
// // }
|
|
// }
|
|
// notifyListeners();
|
|
|
|
// return true;
|
|
// }
|
|
|
|
// String? validateId(String? value) {
|
|
// if (value == null || value.isEmpty) {
|
|
// print("D is required");
|
|
// return 'ID is required';
|
|
// }
|
|
// // Add more validation rules if needed
|
|
// return null;
|
|
// }
|
|
// }
|
|
|
|
import 'dart:convert';
|
|
// import 'dart:html';
|
|
|
|
import 'package:discover_module/contacts_module/ui_screen/interactionform/model/interaction_config_data.dart';
|
|
import 'package:discover_module/contacts_module/ui_screen/interactionform/model/interaction_data.dart';
|
|
import 'package:discover_module/contacts_module/ui_screen/interactionform/model/json_form_data.dart';
|
|
import 'package:discover_module/contacts_module/ui_screen/interactionform/model/location_model.dart';
|
|
import 'package:discover_module/contacts_module/ui_screen/interactionform/model/save_interaction.dart';
|
|
import 'package:discover_module/contacts_module/ui_screen/interactionform/repository/hive_repository.dart';
|
|
import 'package:discover_module/contacts_module/ui_screen/interactionform/util.dart';
|
|
// import 'package:discover_module/ui_screen/interactionform/model/interaction_config_data.dart';
|
|
// import 'package:discover_module/ui_screen/interactionform/model/interaction_data.dart';
|
|
// import 'package:discover_module/ui_screen/interactionform/repository/hive_repository.dart';
|
|
// import 'package:discover_module/ui_screen/interactionform/util.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:hive_flutter/hive_flutter.dart';
|
|
|
|
// import 'package:discover_module/ui_screen/interactionform/model/json_form_data.dart';
|
|
|
|
// import 'package:discover_module/ui_screen/interactionform/model/location_model.dart';
|
|
|
|
// import 'package:discover_module/ui_screen/interactionform/model/save_interaction.dart';
|
|
|
|
class InteractionProvider extends ChangeNotifier {
|
|
List<FormFieldData> interactionReponseList = [];
|
|
// List<dynamic> sectionList = [];
|
|
List<SectionList> sectionList = [];
|
|
late Location locationList;
|
|
List<TextEditingController> textEditingControllerList = [];
|
|
List<TextEditingController> multipletextEditingControllerList = [];
|
|
int textfieldIndex = 0;
|
|
|
|
List<InputClass> checkboxlist = [];
|
|
|
|
String radioValue = '';
|
|
bool checkboxValue = false;
|
|
|
|
//List<InteractionDatum> data = [];
|
|
List<SectionList> newList = [];
|
|
String sectionName = '';
|
|
late String selectedCity = 'Selected City', selectedState = 'Selected State';
|
|
|
|
String? selectedValue;
|
|
List<String> selectedItems = [];
|
|
InputClass? selectedObj;
|
|
List<SaveInteraction> savedList = [];
|
|
List<InteractionConfigData> intConfigDataList = [];
|
|
String? intId, intName;
|
|
final HiveDataRepository _hiveprovider = HiveDataRepository(
|
|
Hive.box<InteractionConfigData>('InteractionConfigDataBox'));
|
|
|
|
late bool _isLoading;
|
|
|
|
get isLoading => _isLoading;
|
|
|
|
initConfigData() async {
|
|
_hiveprovider.openHiveBox();
|
|
intConfigDataList = _hiveprovider.getAllDataFromHive();
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> getRecords() async {
|
|
var box = Hive.box<SaveInteraction>('InteractionDataBox');
|
|
|
|
if (!box.isOpen) {
|
|
box = await Hive.openBox<SaveInteraction>('InteractionDataBox');
|
|
}
|
|
|
|
savedList = box.values.toList();
|
|
print("savedListt: $savedList");
|
|
notifyListeners();
|
|
}
|
|
|
|
init(int index) async {
|
|
await initConfigData();
|
|
InteractionConfigData interactionConfigData = intConfigDataList[index];
|
|
intId = intConfigDataList[index].id;
|
|
intName = intConfigDataList[index].name;
|
|
|
|
radioValue = '';
|
|
print("data $intConfigDataList");
|
|
|
|
await fetchData(interactionConfigData.widgets);
|
|
notifyListeners();
|
|
}
|
|
|
|
initSavedForm(SaveInteraction saveInteractiondata) {
|
|
interactionReponseList = saveInteractiondata.save
|
|
.map((e) => FormFieldData(
|
|
multipleList: e.multipleList == null
|
|
? []
|
|
: e.multipleList!
|
|
.map((mobj) => SectionList(
|
|
depid: mobj.depid,
|
|
id: mobj.id,
|
|
inputList: mobj.inputList,
|
|
isRequired: mobj.isRequired,
|
|
name: mobj.name,
|
|
param: mobj.param,
|
|
selectedValue: mobj.selectedValue,
|
|
fileName: mobj.fileName,
|
|
extension: mobj.extension,
|
|
widget: mobj.widget,
|
|
controller: mobj.controller,
|
|
gid: mobj.gid,
|
|
input: mobj.input,
|
|
selectedId: mobj.selectedId,
|
|
value: mobj.value))
|
|
.toList(),
|
|
sectionList: e.sectionList
|
|
.map((obj) => SectionList(
|
|
depid: obj.depid,
|
|
id: obj.id,
|
|
inputList: obj.inputList,
|
|
isRequired: obj.isRequired,
|
|
name: obj.name,
|
|
param: obj.param,
|
|
fileName: obj.fileName,
|
|
extension: obj.extension,
|
|
selectedValue: obj.selectedValue,
|
|
widget: obj.widget,
|
|
controller: obj.controller,
|
|
gid: obj.gid,
|
|
input: obj.input,
|
|
selectedId: obj.selectedId,
|
|
value: obj.value,
|
|
))
|
|
.toList(),
|
|
sectionName: e.sectionName,
|
|
multiple: e.multiple))
|
|
.toList();
|
|
|
|
textEditingControllerList.clear();
|
|
|
|
for (var item in interactionReponseList) {
|
|
sectionList = item.sectionList;
|
|
for (var sectionItem in item.sectionList) {
|
|
if (sectionItem.widget == InteractionWidget.TEXT) {
|
|
var textEditingController = TextEditingController();
|
|
|
|
textEditingControllerList.add(textEditingController);
|
|
sectionItem.controller = textEditingControllerList.last;
|
|
}
|
|
if (sectionItem.widget == InteractionWidget.DROPDOWN ||
|
|
sectionItem.widget == InteractionWidget.AUTOCOMPLETE ||
|
|
sectionItem.widget == InteractionWidget.MULTISELECT) {
|
|
List<InputClass> list = sectionItem.inputList!;
|
|
sectionItem.value = list[0].id;
|
|
print("value : ${list.first} ");
|
|
}
|
|
}
|
|
}
|
|
print(interactionReponseList);
|
|
print("check textcontrollers ${textEditingControllerList.length}");
|
|
}
|
|
|
|
String getDataValue(String widgetId, String id) {
|
|
print("issue *************");
|
|
if (id != "") {
|
|
List<InputClass> list = [];
|
|
String value = ' ';
|
|
|
|
for (FormFieldData obj1 in interactionReponseList) {
|
|
// List<InputClass> list =
|
|
for (SectionList obj in obj1.sectionList) {
|
|
if (obj.id == widgetId) {
|
|
list = obj.inputList!;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (list.isNotEmpty) {
|
|
int index = list.indexWhere((element) => element.id.toString() == id);
|
|
|
|
if (index != -1) {
|
|
value = list[index].name;
|
|
}
|
|
}
|
|
|
|
return value;
|
|
} else {
|
|
return " ";
|
|
}
|
|
}
|
|
|
|
// TODO: Search for widget with depid and check if selected is not null and by selected id get the data of current widget
|
|
|
|
List<InputClass> getData2(SectionList sectionItem) {
|
|
List<InputClass> list = [];
|
|
// if (sectionItem.inputList != null) {
|
|
list = sectionItem.inputList!;
|
|
if (sectionItem.depid != "") {
|
|
// print("check depid : ${sectionItem.depid}");
|
|
int i = 0;
|
|
for (var obj in interactionReponseList) {
|
|
i = obj.sectionList
|
|
.indexWhere((element) => element.id == sectionItem.depid);
|
|
// print("check depid index: $i");
|
|
if (i != -1) {
|
|
//print("check depid value: ${obj.sectionList[i].value}");
|
|
if (obj.sectionList[i].value != null) {
|
|
if (list
|
|
.where((element) => element.pid == obj.sectionList[i].value)
|
|
.isNotEmpty) {
|
|
list = list
|
|
.where((element) => element.pid == obj.sectionList[i].value)
|
|
.toList();
|
|
|
|
// sectionItem.selectedObject = list[0];
|
|
sectionItem.selectedObject = list[0];
|
|
} else {
|
|
// InputClass obj = InputClass(
|
|
// id: "obj.sectionList[i].value",
|
|
// name: "Select ${sectionItem.name}");
|
|
list = [];
|
|
// list.add(obj);
|
|
sectionItem.selectedObject = null;
|
|
}
|
|
} else {
|
|
// int index = obj.sectionList
|
|
// .indexWhere((element) => element.id == sectionItem.id);
|
|
|
|
// list = obj.sectionList[index].inputList;
|
|
}
|
|
}
|
|
}
|
|
|
|
// int index = data[i].data.indexWhere((element) => element.)
|
|
}
|
|
// }
|
|
return list;
|
|
}
|
|
|
|
setDropDownValue(String value, SectionList sectionItem, bool multiple) {
|
|
int i = 0;
|
|
print("selected $value");
|
|
for (var obj in interactionReponseList) {
|
|
if (multiple && obj.multipleList != null) {
|
|
i = obj.multipleList!
|
|
.indexWhere((element) => element.id == sectionItem.id);
|
|
if (i != -1) {
|
|
obj.multipleList![i].value = value;
|
|
obj.multipleList![i].selectedValue!.add(value);
|
|
}
|
|
} else {
|
|
i = obj.sectionList
|
|
.indexWhere((element) => element.id == sectionItem.id);
|
|
if (i != -1) {
|
|
obj.sectionList[i].value = value;
|
|
obj.sectionList[i].selectedValue!.add(value);
|
|
}
|
|
}
|
|
}
|
|
notifyListeners();
|
|
}
|
|
|
|
setTextValue(String value, SectionList sectionItem, bool multiple) {
|
|
int i = 0;
|
|
for (var obj in interactionReponseList) {
|
|
if (multiple && obj.multipleList != null) {
|
|
i = obj.multipleList!.indexWhere((element) =>
|
|
element.id == sectionItem.id && element.gid == sectionItem.gid);
|
|
if (i != -1) {
|
|
obj.multipleList![i].value = value;
|
|
obj.multipleList![i].selectedValue!.add(value);
|
|
}
|
|
} else {
|
|
i = obj.sectionList
|
|
.indexWhere((element) => element.id == sectionItem.id);
|
|
if (i != -1) {
|
|
obj.sectionList[i].value = value;
|
|
obj.sectionList[i].selectedValue!.add(value);
|
|
}
|
|
}
|
|
}
|
|
notifyListeners();
|
|
}
|
|
|
|
setAutoCompleteValue(String value, SectionList sectionItem, bool multiple) {
|
|
int i = 0;
|
|
for (var obj in interactionReponseList) {
|
|
if (multiple && obj.multipleList != null) {
|
|
i = obj.multipleList!
|
|
.indexWhere((element) => element.id == sectionItem.id);
|
|
if (i != -1) {
|
|
obj.multipleList![i].value = value;
|
|
obj.multipleList![i].selectedValue!.add(value);
|
|
}
|
|
} else {
|
|
i = obj.sectionList
|
|
.indexWhere((element) => element.id == sectionItem.id);
|
|
if (i != -1) {
|
|
obj.sectionList[i].value = value;
|
|
obj.sectionList[i].selectedValue!.add(value);
|
|
}
|
|
}
|
|
}
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<String> fetchData(InteractionResultData interactionResultData) async {
|
|
InteractionResultData interactionConfig = interactionResultData;
|
|
|
|
print("itemCategoryModel Item = + ${interactionConfig.result}");
|
|
// }
|
|
interactionReponseList = interactionConfig.result;
|
|
print("check stored: $interactionReponseList");
|
|
|
|
textEditingControllerList.clear();
|
|
|
|
for (var item in interactionReponseList) {
|
|
sectionList = item.sectionList;
|
|
for (var sectionItem in item.sectionList) {
|
|
sectionItem.selectedValue = [];
|
|
if (sectionItem.widget == InteractionWidget.TEXT) {
|
|
var textEditingController = TextEditingController();
|
|
|
|
textEditingControllerList.add(textEditingController);
|
|
sectionItem.controller = textEditingControllerList.last;
|
|
}
|
|
if (sectionItem.widget == InteractionWidget.DROPDOWN ||
|
|
sectionItem.widget == InteractionWidget.AUTOCOMPLETE ||
|
|
sectionItem.widget == InteractionWidget.MULTISELECT) {
|
|
// int index = data
|
|
// .indexWhere((element) => element.widgetId == sectionItem.id);
|
|
// List<InputClass> list = data[index].data;
|
|
List<InputClass> list = sectionItem.inputList!;
|
|
sectionItem.value = list[0].id;
|
|
if (sectionItem.widget == InteractionWidget.MULTISELECT) {
|
|
sectionItem.selectedValue!.add(list[0].name);
|
|
} else {
|
|
sectionItem.selectedValue!.add(list[0].id);
|
|
}
|
|
|
|
sectionItem.selectedObject = list[0];
|
|
print("value : ${list.first} ");
|
|
} else if (sectionItem.widget == InteractionWidget.CHECKBOX) {
|
|
List<InputClass> list = sectionItem.inputList!;
|
|
if (list.isNotEmpty) {
|
|
for (var element in sectionItem.inputList!) {
|
|
element.ischecked = false;
|
|
}
|
|
}
|
|
// sectionItem.value = list[0].id;
|
|
// sectionItem.selectedValue!.add(list[0].id);
|
|
}
|
|
}
|
|
}
|
|
print(interactionReponseList);
|
|
print("check textcontrollers ${textEditingControllerList.length}");
|
|
notifyListeners();
|
|
|
|
return "success";
|
|
}
|
|
|
|
resetAllWidgetsData() {
|
|
textEditingControllerList.clear();
|
|
|
|
for (var item in interactionReponseList) {
|
|
item.multipleList = [];
|
|
sectionList = item.sectionList;
|
|
for (var sectionItem in item.sectionList) {
|
|
sectionItem.selectedValue = [];
|
|
// sectionItem.value = '';
|
|
// sectionItem.selectedObject = InputClass(id: '', name: '');
|
|
if (sectionItem.widget == InteractionWidget.TEXT) {
|
|
var textEditingController = TextEditingController();
|
|
|
|
textEditingControllerList.add(textEditingController);
|
|
sectionItem.controller = textEditingControllerList.last;
|
|
}
|
|
if (item.sectionName != "Other") {
|
|
if (sectionItem.widget == InteractionWidget.DROPDOWN ||
|
|
sectionItem.widget == InteractionWidget.AUTOCOMPLETE ||
|
|
sectionItem.widget == InteractionWidget.MULTISELECT) {
|
|
// int index = data
|
|
// .indexWhere((element) => element.widgetId == sectionItem.id);
|
|
print("Selected widget : ${sectionItem.id}");
|
|
List<InputClass> list = sectionItem.inputList!;
|
|
sectionItem.value = list[0].id;
|
|
sectionItem.selectedObject = list[0];
|
|
print("value : ${list.first.name} ");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
print(interactionReponseList);
|
|
print("check textcontrollers ${textEditingControllerList.length}");
|
|
notifyListeners();
|
|
}
|
|
|
|
setRadioValue(SectionList sectionItem) {
|
|
List<InputClass> list = (sectionItem.input as List)
|
|
.map((itemWord) => InputClass.fromJson(itemWord))
|
|
.toList();
|
|
radioValue = list[0].name;
|
|
|
|
notifyListeners();
|
|
}
|
|
|
|
setcheckBoxValue(SectionList sectionItem, String sectionName, bool newValue,
|
|
String id, bool multiple) {
|
|
int index =
|
|
sectionItem.inputList!.indexWhere((element) => element.id == id);
|
|
sectionItem.inputList![index].ischecked = newValue;
|
|
// sectionItem.selectedValue.add(data[i].data[index].id);
|
|
int index2 = 0;
|
|
for (var obj in interactionReponseList) {
|
|
if (multiple && obj.multipleList != null) {
|
|
index2 = obj.multipleList!
|
|
.indexWhere((element) => element.id == sectionItem.id);
|
|
if (index2 != -1) {
|
|
obj.multipleList![index2].value = sectionItem.inputList![index].id;
|
|
obj.multipleList![index2].selectedValue!
|
|
.add(sectionItem.inputList![index].id);
|
|
}
|
|
} else {
|
|
index2 = obj.sectionList
|
|
.indexWhere((element) => element.id == sectionItem.id);
|
|
if (index2 != -1) {
|
|
obj.sectionList[index2].value = sectionItem.inputList![index].id;
|
|
obj.sectionList[index2].selectedValue!
|
|
.add(sectionItem.inputList![index].id);
|
|
}
|
|
}
|
|
}
|
|
notifyListeners();
|
|
}
|
|
|
|
getSectionItem(String sectionName) {
|
|
newList = [];
|
|
List<SectionList> addList = [];
|
|
int index = interactionReponseList
|
|
.indexWhere((element) => element.sectionName == sectionName);
|
|
var textEditingController = TextEditingController();
|
|
addList = interactionReponseList[index]
|
|
.sectionList
|
|
.map((e) => SectionList(
|
|
depid: e.depid,
|
|
id: e.id,
|
|
inputList: e.inputList,
|
|
isRequired: e.isRequired,
|
|
name: e.name,
|
|
validation: e.validation,
|
|
param: e.param,
|
|
selectedValue: [],
|
|
widget: e.widget,
|
|
controller: e.controller,
|
|
gid: e.gid,
|
|
input: e.input,
|
|
selectedId: e.selectedId,
|
|
value: e.value))
|
|
.toList();
|
|
SectionList delItem = SectionList(
|
|
name: " ",
|
|
param: "deletebtn",
|
|
id: "deletebtn",
|
|
selectedValue: [],
|
|
depid: "",
|
|
widget: InteractionWidget.BUTTON,
|
|
inputList: [],
|
|
validation: Validation(isRequired: false),
|
|
isRequired: true);
|
|
|
|
addList.add(delItem);
|
|
|
|
for (SectionList obj in addList) {
|
|
//obj.gid = obj.gid ?? addList.length;
|
|
if (obj.widget == InteractionWidget.TEXT) {
|
|
// multipletextEditingControllerList.clear();
|
|
var textEditingController = TextEditingController();
|
|
obj.controller = textEditingController;
|
|
multipletextEditingControllerList.add(textEditingController);
|
|
}
|
|
// newList.add(obj);
|
|
}
|
|
|
|
// if (interactionReponseList[index].multipleList!.isEmpty) {
|
|
// newList = addList;
|
|
// } else {
|
|
if (interactionReponseList[index].multipleList == null) {
|
|
interactionReponseList[index].multipleList = addList;
|
|
} else {
|
|
interactionReponseList[index].multipleList =
|
|
interactionReponseList[index].multipleList! + addList;
|
|
}
|
|
|
|
newList = interactionReponseList[index].multipleList!;
|
|
// newList = newList + addList;
|
|
// }
|
|
if (interactionReponseList[index].multipleList != null) {
|
|
for (SectionList obj in interactionReponseList[index].multipleList!) {
|
|
obj.gid = obj.gid ?? interactionReponseList[index].multipleList!.length;
|
|
// if (obj.widget == InteractionWidget.TEXT) {
|
|
// var textEditingController = TextEditingController();
|
|
|
|
// multipletextEditingControllerList.add(textEditingController);
|
|
// obj.controller = multipletextEditingControllerList.last;
|
|
// }
|
|
//newList.add(obj);
|
|
}
|
|
}
|
|
|
|
print(
|
|
"check length : ${interactionReponseList[index].multipleList!.length}");
|
|
notifyListeners();
|
|
}
|
|
|
|
deleteMultipleRows(
|
|
int gid, SectionList sectionItem, String selectedSectionName) {
|
|
int index = interactionReponseList
|
|
.indexWhere((element) => element.sectionName == selectedSectionName);
|
|
|
|
print("controllerssssss : ${multipletextEditingControllerList.length}");
|
|
interactionReponseList[index]
|
|
.multipleList!
|
|
.removeWhere((item) => item.gid == gid);
|
|
|
|
notifyListeners();
|
|
}
|
|
|
|
bool validateMultipleRows() {
|
|
for (var obj in interactionReponseList) {
|
|
if (obj.multipleList != null) {
|
|
for (var mulobj in obj.multipleList!) {
|
|
if (mulobj.widget == InteractionWidget.TEXT) {
|
|
if (mulobj.controller!.text.isEmpty) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool validateTextFields() {
|
|
for (var obj in interactionReponseList) {
|
|
for (var mulobj in obj.sectionList) {
|
|
if (mulobj.widget == InteractionWidget.TEXT) {
|
|
if (mulobj.controller!.text.isEmpty) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
Future<String> saveJsonObject(BuildContext context, String form,
|
|
{bool isEdit = false}) async {
|
|
print("form_data: $form");
|
|
// for (var ob in interactionReponseList) {
|
|
|
|
// for (var ob2 in ob.multipleList!) {
|
|
// debugPrint("!!!!!!!!!!!!In multiple :${ob2.selectedValue}");
|
|
// }
|
|
// }
|
|
List<FormFieldData> resultData = interactionReponseList
|
|
.map((e) => FormFieldData(
|
|
multipleList: e.multipleList == null
|
|
? []
|
|
: e.multipleList!
|
|
.map((mobj) => SectionList(
|
|
depid: mobj.depid,
|
|
validation:
|
|
Validation(isRequired: mobj.validation!.isRequired),
|
|
id: mobj.id,
|
|
inputList: mobj.inputList,
|
|
isRequired: mobj.validation!.isRequired,
|
|
name: mobj.name,
|
|
param: mobj.param,
|
|
selectedValue: mobj.selectedValue,
|
|
extension: mobj.extension,
|
|
fileName: mobj.fileName,
|
|
widget: mobj.widget,
|
|
// controller: mobj.controller,
|
|
gid: mobj.gid,
|
|
input: mobj.input,
|
|
selectedId: mobj.selectedId,
|
|
value: mobj.value))
|
|
.toList(),
|
|
sectionList: e.sectionList
|
|
.map((obj) => SectionList(
|
|
depid: obj.depid,
|
|
id: obj.id,
|
|
validation:
|
|
Validation(isRequired: obj.validation!.isRequired),
|
|
inputList: obj.inputList,
|
|
isRequired: obj.validation!.isRequired,
|
|
name: obj.name,
|
|
param: obj.param,
|
|
selectedValue: obj.selectedValue,
|
|
widget: obj.widget,
|
|
controller: obj.controller,
|
|
gid: obj.gid,
|
|
input: obj.input,
|
|
extension: obj.extension,
|
|
fileName: obj.fileName,
|
|
selectedId: obj.selectedId,
|
|
value: obj.value))
|
|
.toList(),
|
|
sectionName: e.sectionName,
|
|
multiple: e.multiple))
|
|
.toList();
|
|
|
|
String generateId = '${intId}R${await getNextAutoIncrementValue()}';
|
|
if (validateSectionList(resultData)) {
|
|
_isLoading = true;
|
|
notifyListeners();
|
|
final data = SaveInteraction(
|
|
save: resultData,
|
|
id: generateId,
|
|
updatedTime: DateTime.now().toString(),
|
|
form: form,
|
|
intId: intId ?? "id",
|
|
intName: intName ?? "name");
|
|
var box = Hive.box<SaveInteraction>('InteractionDataBox');
|
|
|
|
if (!box.isOpen) {
|
|
box = await Hive.openBox<SaveInteraction>('InteractionDataBox');
|
|
}
|
|
|
|
print("Data_Result_is: ${data}");
|
|
|
|
// // if (validateJson1(data.save.first)) {
|
|
await box.put(await getNextAutoIncrementValue(), data);
|
|
} else {
|
|
_isLoading = false;
|
|
notifyListeners();
|
|
|
|
// Handle validation error
|
|
print("JSON data is not valid according to the schema.");
|
|
}
|
|
await getRecords();
|
|
return generateId;
|
|
|
|
// final data = SaveInteraction(
|
|
// save: resultData,
|
|
// id: generateId,
|
|
// updatedTime: DateTime.now().toString(),
|
|
// form: form,
|
|
// intId: intId ?? "id",
|
|
// intName: intName ?? "name");
|
|
// var box = Hive.box<SaveInteraction>('InteractionDataBox');
|
|
|
|
// if (!box.isOpen) {
|
|
// box = await Hive.openBox<SaveInteraction>('InteractionDataBox');
|
|
// }
|
|
|
|
// await box.put(await getNextAutoIncrementValue(), data);
|
|
// // box.close();
|
|
// await getRecords();
|
|
// return generateId;
|
|
// await MockApiCall().postFormData(data);
|
|
// await prov.addOfflineData(data);
|
|
}
|
|
|
|
List<MultipleSectionList> getModifiedList(List<SectionList> sectionList) {
|
|
List<MultipleSectionList> newSectionList = [];
|
|
for (var obj in sectionList) {
|
|
if (obj.id != 'deletebtn') {
|
|
if (obj.input == 'chooseFile') {
|
|
MultipleSectionList newobj = MultipleSectionList(
|
|
id: obj.id,
|
|
selectedValue: obj.selectedValue!,
|
|
extension: obj.extension!,
|
|
fileName: obj.fileName!,
|
|
);
|
|
|
|
newSectionList.add(newobj);
|
|
} else {
|
|
MultipleSectionList newobj = MultipleSectionList(
|
|
id: obj.id,
|
|
selectedValue: obj.selectedValue!,
|
|
);
|
|
newSectionList.add(newobj);
|
|
}
|
|
}
|
|
}
|
|
return newSectionList;
|
|
}
|
|
|
|
List<List<MultipleSectionList>> getMultipleSectionList(
|
|
List<SectionList> sectionList, List<SectionList> multipleList) {
|
|
List<List<MultipleSectionList>> list = [];
|
|
List<List<MultipleSectionList>> listing = [];
|
|
List<MultipleSectionList> secList = getModifiedList(sectionList);
|
|
List<MultipleSectionList> multipleList0 = getModifiedList(multipleList);
|
|
list.add(secList);
|
|
listing.add(secList);
|
|
// List<SectionList> listing = [];
|
|
if (multipleList.isNotEmpty) {
|
|
final releaseDateMap = multipleList.groupBy((m) => m.gid);
|
|
print("see map : $releaseDateMap");
|
|
|
|
if (releaseDateMap.isNotEmpty) {
|
|
listing = [];
|
|
List<List<SectionList>> mulList =
|
|
releaseDateMap.values.toList(growable: true);
|
|
for (var item in mulList) {
|
|
listing.add(getModifiedList(item));
|
|
}
|
|
listing.add(secList);
|
|
list = [...listing];
|
|
|
|
//});
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
SaveInteractionFormJson formJson(SaveInteraction saveInteraction) {
|
|
List<Save> saveList = [];
|
|
for (var obj in saveInteraction.save) {
|
|
Save saveobj = Save(
|
|
sectionName: obj.sectionName,
|
|
multipleSectionList:
|
|
getMultipleSectionList(obj.sectionList, obj.multipleList!));
|
|
saveList.add(saveobj);
|
|
}
|
|
|
|
SaveInteractionFormJson saveInteractionFormJson = SaveInteractionFormJson(
|
|
interactionForm1: saveInteraction.form!,
|
|
intId: saveInteraction.id,
|
|
intName: saveInteraction.intName,
|
|
save: saveList);
|
|
return saveInteractionFormJson;
|
|
}
|
|
|
|
bool validateSectionList(List<FormFieldData> resultData) {
|
|
for (var formData in resultData) {
|
|
for (var section in formData.sectionList) {
|
|
// print("Section.leangthiss: ${resultData.length}");
|
|
// for (int i = 0; i <= resultData.length; i++) {
|
|
// SectionList sectionItem = formData.sectionList[i];
|
|
// print("Section_isssss1111: ${sectionItem.validation!.isRequired}");
|
|
// }
|
|
|
|
print("Section_isssss: $section");
|
|
print("Section_isssss: ${section.widget}");
|
|
print("Section_isssss: ${section.selectedId}");
|
|
print("Section_isssss1111: ${section.isRequired},${section.name}");
|
|
|
|
if (section.widget == InteractionWidget.TEXT) {
|
|
// if (section.controller!.text.isEmpty) {
|
|
if (section.isRequired == true && section.controller!.text.isEmpty) {
|
|
debugPrint("Iam text and empty");
|
|
notifyListeners();
|
|
|
|
return false;
|
|
}
|
|
} else if (section.widget == InteractionWidget.AUTOCOMPLETE) {
|
|
if (section.isRequired == true && section.selectedValue!.isEmpty) {
|
|
debugPrint("Iam AUTOCOMPLETE and empty");
|
|
notifyListeners();
|
|
|
|
return false;
|
|
}
|
|
} else if (section.widget == InteractionWidget.DROPDOWN) {
|
|
if (section.isRequired == true && section.selectedValue!.isEmpty) {
|
|
debugPrint("Iam dropdown and empty");
|
|
notifyListeners();
|
|
|
|
return false;
|
|
}
|
|
} else if (section.widget == InteractionWidget.CHECKBOX) {
|
|
if (section.isRequired == true && section.selectedValue!.isEmpty) {
|
|
debugPrint("Iam CHECKBOX and empty");
|
|
notifyListeners();
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
print("Multilist");
|
|
for (var msection in formData.multipleList!) {
|
|
print("Multilist Enter");
|
|
|
|
print("Multilist Enterwidget: ${msection.widget}");
|
|
|
|
if (msection.isRequired == true &&
|
|
msection.widget == InteractionWidget.TEXT) {
|
|
print("Checkinggg: ${msection.id}");
|
|
print("Checkinggg: ${msection.depid}");
|
|
print("Checkinggg: ${msection.chars}");
|
|
print("Checkinggg: ${msection.selectedId}");
|
|
print("Checkinggg: ${msection.selectedValue!}");
|
|
|
|
if (msection.isRequired == true && msection.selectedValue!.isEmpty) {
|
|
debugPrint("Iam multi text and empty");
|
|
notifyListeners();
|
|
|
|
return false;
|
|
}
|
|
} else if (msection.widget == InteractionWidget.AUTOCOMPLETE) {
|
|
if (msection.isRequired == true && msection.selectedValue!.isEmpty) {
|
|
debugPrint("Iam AUTOCOMPLETE and empty");
|
|
notifyListeners();
|
|
|
|
return false;
|
|
}
|
|
} else if (msection.widget == InteractionWidget.DROPDOWN) {
|
|
if (msection.isRequired == true && msection.selectedValue!.isEmpty) {
|
|
debugPrint("Iam dropdown and empty ${msection.widget}");
|
|
notifyListeners();
|
|
|
|
return false;
|
|
}
|
|
} else if (msection.widget == InteractionWidget.CHECKBOX) {
|
|
if (msection.isRequired == true && msection.selectedValue!.isEmpty) {
|
|
debugPrint("Iam CHECKBOX and empty");
|
|
notifyListeners();
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
notifyListeners();
|
|
|
|
return true;
|
|
}
|
|
}
|