votePoll method

Future<MBPollVoteResponse> votePoll(
  1. int pollId,
  2. int answerIndex
)

Votes for a poll.

  • Parameters:
    • pollId: the id of the poll element.
    • answerIndex: this index of the answer voted for.
  • Returns a Future that completes with the MBPollVoteResponse posted to MBurger.

Implementation

Future<MBPollVoteResponse> votePoll(int pollId, int answerIndex) async {
  Map<String, dynamic> apiParameters = {};

  apiParameters['element_id'] = pollId.toString();
  apiParameters['vote'] = answerIndex.toString();

  apiParameters.addAll(await defaultParameters());

  String apiName = 'api/vote-poll';

  var requestBody = json.encode(apiParameters);

  var uri = Uri.https(endpoint, apiName);

  http.Response response = await http.post(
    uri,
    headers: await headers(contentTypeJson: true),
    body: requestBody,
  );

  Map<String, dynamic> body = MBManager.checkResponse(response.body);
  return MBPollVoteResponse(dictionary: body);
}