toggleChoice function

dynamic toggleChoice(
  1. Question q,
  2. dynamic value,
  3. String id
)

Implementation

dynamic toggleChoice(Question q, dynamic value, String id) {
  final option=q.options.firstWhere((o)=>o['id']==id),current=selectedChoices(value);
  final selected=q.type=='single_choice' ? [id] : current.contains(id) ? current.where((v)=>v!=id).toList() : option['exclusive']==true ? [id] : [...current.where((v)=>!q.options.any((o)=>o['id']==v && o['exclusive']==true)),id];
  return choiceAnswer(q,selected,otherTexts(value));
}