setState method

void setState(
  1. Map<String, dynamic> doc
)

This method is used to set the state of the cards containing the questions and answers.

It accepts a parameter doc of type Map<String,String> which essentially contains an unordered list of question:answer key:value pairs typically fetched from a database. This method sets the state and arranges the questions according to the order specified by the _questionStructure variable.

Implementation

void setState(Map<String, dynamic> doc) {
  this.resetState();
  for (int i = 0; i < _expanded.length; i++) {
    doc.keys.forEach((field) {
      if (_expanded[i].keys.toList()[0].toString() == field) {
        if (!(_expanded[i].keys.toList()[0] is NestedQuestion ||
            _expanded[i].keys.toList()[0] is PolarQuestion))
          _expanded[i].keys.toList()[0].answer.text = doc[field];

        this.onEvent(_expanded[i], doc[field]);
      }
    });
  }
}