generateAnswerBody static method

String generateAnswerBody(
  1. List<AskUserChoice> options,
  2. String? answer
)

Implementation

static String generateAnswerBody(
  List<AskUserChoice> options,
  String? answer,
) {
  if (options.isNotEmpty) {
    List<int> indices = options.asMap().keys.toList();
    List<String> values = options.map((option) => option.choice).toList();
    return jsonEncode({
      "choice": {"index": indices, "value": values},
    });
  } else if (answer != null) {
    return jsonEncode({
      "choice": {"value": answer},
    });
  } else {
    return jsonEncode({"choice": {}});
  }
}