MBPollVoteResponse constructor

MBPollVoteResponse({
  1. required Map<String, dynamic> dictionary,
})

Initializes a vote poll response with the dictionary returned by the MBurger APIs.

  • Parameters:
    • dictionary: The dictionary returned by the APIs.

Implementation

factory MBPollVoteResponse({required Map<String, dynamic> dictionary}) {
  int myVoteIndex = 0;
  List<int> votes = [];
  if (dictionary["mine"] is String) {
    myVoteIndex = int.tryParse(dictionary["mine"] as String) ?? 0;
  } else if (dictionary["mine"] is int) {
    myVoteIndex = dictionary["mine"] as int;
  }
  if (dictionary["results"] != null) {
    List<dynamic> dynamicRes = dictionary["results"] as List;
    for (dynamic res in dynamicRes) {
      if (res is int) {
        votes.add(res);
      } else {
        votes.add(0);
      }
    }
  }
  return MBPollVoteResponse._(
    myVoteIndex: myVoteIndex,
    votes: votes,
  );
}