2024-10-07 12:41:28 +00:00
|
|
|
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';
|
2024-11-22 10:38:43 +00:00
|
|
|
|
2024-05-20 10:29:02 +00:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:hive_flutter/hive_flutter.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'));
|
|
|
|
|
2024-06-10 11:11:00 +00:00
|
|
|
late bool _isLoading;
|
|
|
|
|
|
|
|
get isLoading => _isLoading;
|
|
|
|
|
2024-05-20 10:29:02 +00:00
|
|
|
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();
|
|
|
|
|
2024-06-24 11:36:09 +00:00
|
|
|
// sectionItem.selectedObject = list[0];
|
2024-05-20 10:29:02 +00:00
|
|
|
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) {
|
2024-06-10 11:11:00 +00:00
|
|
|
i = obj.multipleList!.indexWhere((element) =>
|
|
|
|
element.id == sectionItem.id && element.gid == sectionItem.gid);
|
2024-05-20 10:29:02 +00:00
|
|
|
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);
|
2024-06-10 11:11:00 +00:00
|
|
|
var textEditingController = TextEditingController();
|
2024-05-20 10:29:02 +00:00
|
|
|
addList = interactionReponseList[index]
|
|
|
|
.sectionList
|
|
|
|
.map((e) => SectionList(
|
|
|
|
depid: e.depid,
|
|
|
|
id: e.id,
|
|
|
|
inputList: e.inputList,
|
|
|
|
isRequired: e.isRequired,
|
|
|
|
name: e.name,
|
2024-06-24 11:36:09 +00:00
|
|
|
validation: e.validation,
|
2024-05-20 10:29:02 +00:00
|
|
|
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(
|
2024-06-24 11:36:09 +00:00
|
|
|
name: " ",
|
2024-05-20 10:29:02 +00:00
|
|
|
param: "deletebtn",
|
|
|
|
id: "deletebtn",
|
|
|
|
selectedValue: [],
|
|
|
|
depid: "",
|
|
|
|
widget: InteractionWidget.BUTTON,
|
|
|
|
inputList: [],
|
2024-06-24 11:36:09 +00:00
|
|
|
validation: Validation(isRequired: false),
|
2024-05-20 10:29:02 +00:00
|
|
|
isRequired: true);
|
|
|
|
|
|
|
|
addList.add(delItem);
|
|
|
|
|
2024-06-10 11:11:00 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-05-20 10:29:02 +00:00
|
|
|
// 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;
|
2024-06-10 11:11:00 +00:00
|
|
|
// if (obj.widget == InteractionWidget.TEXT) {
|
|
|
|
// var textEditingController = TextEditingController();
|
2024-05-20 10:29:02 +00:00
|
|
|
|
2024-06-10 11:11:00 +00:00
|
|
|
// multipletextEditingControllerList.add(textEditingController);
|
|
|
|
// obj.controller = multipletextEditingControllerList.last;
|
|
|
|
// }
|
|
|
|
//newList.add(obj);
|
2024-05-20 10:29:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
2024-06-10 11:11:00 +00:00
|
|
|
// for (var ob in interactionReponseList) {
|
|
|
|
|
|
|
|
// for (var ob2 in ob.multipleList!) {
|
|
|
|
// debugPrint("!!!!!!!!!!!!In multiple :${ob2.selectedValue}");
|
|
|
|
// }
|
|
|
|
// }
|
2024-05-20 10:29:02 +00:00
|
|
|
List<FormFieldData> resultData = interactionReponseList
|
|
|
|
.map((e) => FormFieldData(
|
|
|
|
multipleList: e.multipleList == null
|
|
|
|
? []
|
|
|
|
: e.multipleList!
|
|
|
|
.map((mobj) => SectionList(
|
|
|
|
depid: mobj.depid,
|
2024-06-24 11:36:09 +00:00
|
|
|
validation:
|
|
|
|
Validation(isRequired: mobj.validation!.isRequired),
|
2024-05-20 10:29:02 +00:00
|
|
|
id: mobj.id,
|
|
|
|
inputList: mobj.inputList,
|
2024-06-24 11:36:09 +00:00
|
|
|
isRequired: mobj.validation!.isRequired,
|
2024-05-20 10:29:02 +00:00
|
|
|
name: mobj.name,
|
|
|
|
param: mobj.param,
|
|
|
|
selectedValue: mobj.selectedValue,
|
|
|
|
extension: mobj.extension,
|
|
|
|
fileName: mobj.fileName,
|
|
|
|
widget: mobj.widget,
|
2024-06-10 11:11:00 +00:00
|
|
|
// controller: mobj.controller,
|
2024-05-20 10:29:02 +00:00
|
|
|
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,
|
2024-06-24 11:36:09 +00:00
|
|
|
validation:
|
|
|
|
Validation(isRequired: obj.validation!.isRequired),
|
2024-05-20 10:29:02 +00:00
|
|
|
inputList: obj.inputList,
|
2024-06-24 11:36:09 +00:00
|
|
|
isRequired: obj.validation!.isRequired,
|
2024-05-20 10:29:02 +00:00
|
|
|
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()}';
|
2024-06-10 11:11:00 +00:00
|
|
|
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');
|
|
|
|
}
|
2024-05-20 10:29:02 +00:00
|
|
|
|
2024-06-10 11:11:00 +00:00
|
|
|
print("Data_Result_is: ${data}");
|
2024-05-20 10:29:02 +00:00
|
|
|
|
2024-06-10 11:11:00 +00:00
|
|
|
// // if (validateJson1(data.save.first)) {
|
|
|
|
await box.put(await getNextAutoIncrementValue(), data);
|
|
|
|
} else {
|
|
|
|
_isLoading = false;
|
|
|
|
notifyListeners();
|
2024-05-20 10:29:02 +00:00
|
|
|
|
2024-06-10 11:11:00 +00:00
|
|
|
// Handle validation error
|
|
|
|
print("JSON data is not valid according to the schema.");
|
|
|
|
}
|
2024-05-20 10:29:02 +00:00
|
|
|
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;
|
|
|
|
}
|
2024-06-10 11:11:00 +00:00
|
|
|
|
|
|
|
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}");
|
2024-06-24 11:36:09 +00:00
|
|
|
print("Section_isssss1111: ${section.isRequired},${section.name}");
|
2024-06-10 11:11:00 +00:00
|
|
|
|
|
|
|
if (section.widget == InteractionWidget.TEXT) {
|
2024-06-24 11:36:09 +00:00
|
|
|
// if (section.controller!.text.isEmpty) {
|
|
|
|
if (section.isRequired == true && section.controller!.text.isEmpty) {
|
2024-06-10 11:11:00 +00:00
|
|
|
debugPrint("Iam text and empty");
|
|
|
|
notifyListeners();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (section.widget == InteractionWidget.AUTOCOMPLETE) {
|
2024-06-24 11:36:09 +00:00
|
|
|
if (section.isRequired == true && section.selectedValue!.isEmpty) {
|
2024-06-10 11:11:00 +00:00
|
|
|
debugPrint("Iam AUTOCOMPLETE and empty");
|
|
|
|
notifyListeners();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (section.widget == InteractionWidget.DROPDOWN) {
|
2024-06-24 11:36:09 +00:00
|
|
|
if (section.isRequired == true && section.selectedValue!.isEmpty) {
|
2024-06-10 11:11:00 +00:00
|
|
|
debugPrint("Iam dropdown and empty");
|
|
|
|
notifyListeners();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (section.widget == InteractionWidget.CHECKBOX) {
|
2024-06-24 11:36:09 +00:00
|
|
|
if (section.isRequired == true && section.selectedValue!.isEmpty) {
|
2024-06-10 11:11:00 +00:00
|
|
|
debugPrint("Iam CHECKBOX and empty");
|
|
|
|
notifyListeners();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print("Multilist");
|
|
|
|
for (var msection in formData.multipleList!) {
|
|
|
|
print("Multilist Enter");
|
|
|
|
|
|
|
|
print("Multilist Enterwidget: ${msection.widget}");
|
|
|
|
|
2024-06-24 11:36:09 +00:00
|
|
|
if (msection.isRequired == true &&
|
|
|
|
msection.widget == InteractionWidget.TEXT) {
|
2024-06-10 11:11:00 +00:00
|
|
|
print("Checkinggg: ${msection.id}");
|
|
|
|
print("Checkinggg: ${msection.depid}");
|
|
|
|
print("Checkinggg: ${msection.chars}");
|
|
|
|
print("Checkinggg: ${msection.selectedId}");
|
|
|
|
print("Checkinggg: ${msection.selectedValue!}");
|
|
|
|
|
2024-06-24 11:36:09 +00:00
|
|
|
if (msection.isRequired == true && msection.selectedValue!.isEmpty) {
|
2024-06-10 11:11:00 +00:00
|
|
|
debugPrint("Iam multi text and empty");
|
|
|
|
notifyListeners();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (msection.widget == InteractionWidget.AUTOCOMPLETE) {
|
2024-06-24 11:36:09 +00:00
|
|
|
if (msection.isRequired == true && msection.selectedValue!.isEmpty) {
|
2024-06-10 11:11:00 +00:00
|
|
|
debugPrint("Iam AUTOCOMPLETE and empty");
|
|
|
|
notifyListeners();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (msection.widget == InteractionWidget.DROPDOWN) {
|
2024-06-24 11:36:09 +00:00
|
|
|
if (msection.isRequired == true && msection.selectedValue!.isEmpty) {
|
|
|
|
debugPrint("Iam dropdown and empty ${msection.widget}");
|
2024-06-10 11:11:00 +00:00
|
|
|
notifyListeners();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (msection.widget == InteractionWidget.CHECKBOX) {
|
2024-06-24 11:36:09 +00:00
|
|
|
if (msection.isRequired == true && msection.selectedValue!.isEmpty) {
|
2024-06-10 11:11:00 +00:00
|
|
|
debugPrint("Iam CHECKBOX and empty");
|
|
|
|
notifyListeners();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
notifyListeners();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2024-05-20 10:29:02 +00:00
|
|
|
}
|