createAnswerPayloadOtherSurvey function
dynamic
createAnswerPayloadOtherSurvey(
- dynamic obj,
- dynamic surArr
Implementation
createAnswerPayloadOtherSurvey(obj, surArr) {
if (!(obj is CustomRating ||
obj is CustomEmailInput ||
obj is CustomMultiChoice ||
obj is CustomTextInput ||
obj is CustomYesNo ||
obj is CustomOpinionScale ||
obj is CustomPhoneNumber)) {
throw Exception(
'obj has to be a instance of CustomRating or CustomEmailInput or CustomPhoneNumber or CustomOpnionScale');
}
var currentAns = {};
var isAnswerCollected = surArr.where((e) => e['question_id'] == obj.key);
if (isAnswerCollected.length > 0) {
currentAns = isAnswerCollected.first;
if (obj.skipped) {
currentAns[obj.name]['data'] = null;
currentAns[obj.name]['skipped'] = obj.skipped;
} else {
currentAns[obj.name]['data'] = obj.data;
currentAns[obj.name]['skipped'] = obj.skipped;
}
} else {
if (obj.skipped) {
currentAns['question_id'] = obj.key;
currentAns[obj.name] = {};
currentAns[obj.name]['data'] = obj.data;
currentAns[obj.name]['skipped'] = obj.skipped;
currentAns[obj.name]['timeTaken'] = obj.timeTaken;
} else {
currentAns['question_id'] = obj.key;
currentAns[obj.name] = {};
currentAns[obj.name]['data'] = obj.data;
currentAns[obj.name]['skipped'] = obj.skipped;
currentAns[obj.name]['timeTaken'] = obj.timeTaken;
}
surArr.add(currentAns);
}
}