toggleChoice method

void toggleChoice(
  1. String questionId,
  2. String value
)

Toggle a value within a multi-select answer.

Implementation

void toggleChoice(String questionId, String value) {
  final current =
      (answers[questionId] as List?)?.cast<String>() ?? <String>[];
  final next = [...current];
  next.contains(value) ? next.remove(value) : next.add(value);
  answers[questionId] = next;
  notifyListeners();
}