startPoll method

Future<String?> startPoll({
  1. required String question,
  2. required List<PollAnswer> answers,
  3. String? body,
  4. PollKind kind = PollKind.undisclosed,
  5. int maxSelections = 1,
  6. String? txid,
})

Implementation

Future<String?> startPoll({
  required String question,
  required List<PollAnswer> answers,
  String? body,
  PollKind kind = PollKind.undisclosed,
  int maxSelections = 1,
  String? txid,
}) async {
  if (answers.length > 20) {
    throw Exception('Client must not set more than 20 answers in a poll');
  }

  if (body == null) {
    body = question;
    for (var i = 0; i < answers.length; i++) {
      body = '$body\n$i. ${answers[i].mText}';
    }
  }

  final newPollEvent = PollEventContent(
    mText: body!,
    pollStartContent: PollStartContent(
      kind: kind,
      maxSelections: maxSelections,
      question: PollQuestion(mText: question),
      answers: answers,
    ),
  );

  return sendEvent(
    newPollEvent.toJson(),
    type: PollEventContent.startType,
    txid: txid,
  );
}