addData method

void addData(
  1. Map<String, dynamic> jsonObject
)

Implementation

void addData(Map<String, dynamic> jsonObject) {
  try {
    List<AnswerModel> optionList = [];
    QuestionModel questionModel = QuestionModel(
      pollConst: jsonObject['id'],
      pollId: jsonObject['id'],
      questionTitle: jsonObject['question'],
      totalPollCount: jsonObject['total_result'],

      duration: jsonObject['duration'],


    );

    Map<String, dynamic> options = jsonObject['options'];
    options.forEach((key, value) {
      int percentage = (jsonObject['total_result'] != 0)
          ? (jsonObject['result'][key] / jsonObject['total_result'] * 100).toInt()
          : 0;
      optionList.add(AnswerModel(
        title: value,
        percentage: percentage,
        numberOfPoll: jsonObject['result'][key],
        userName: "",
        userRef: "",
        clientId: "",
      ));
    });

    _expandableDetailList[questionModel] = optionList;
  } catch (e) {
    print("Error adding data: $e");
  }
}