withAnswer function

String withAnswer(
  1. String text,
  2. String questionId,
  3. String answer, {
  4. String? at,
})

text with the answer of question questionId set to answer ('' clears it), its label carrying the change time at (SOM §11.9.10) or, with none, written untimed as **Answer:** — an import writes what its source held, and a time it would add would be its own, not the answer's.

Throws SpecReviewAnnotationError when text has no such question, or when at is not a time.

Implementation

String withAnswer(String text, String questionId, String answer, {String? at}) {
  final annotations = _annotationsOf(text)
    ..setAnswer(questionId, answer, at: at ?? _untimed);
  final out = annotations.doc.content(_value) ?? '';
  return at == null ? out.replaceFirst(_untimedLabel, '**Answer:**') : out;
}