0

在这里,我从 API 中获取了字符串值。该字符串是使用 Provider 类和 Access 使用消费者收集的。它正确地穿上了绳子。但是该字符串的数字不断变化,我无法阻止我在这里附上了这个问题的视频。

文本小部件:

Text(
              mcq.selectedMCQ.questionTitle,
              style: TextStyle(fontSize: 20),
            ),

提供者:

未来 getFetchQuestion(String questionId) async{

var url = Uri.parse('${BaseUrl.url}/MobileAPI/getQuestionByID/$questionId');
var response = await http.get(
  url,

  headers: {
    "Content-Type": "application/json",
  },
);

if (response.statusCode == 200) {
  final responseData = json.decode(response.body);

  MCQ result =
  MCQ.fromJson(responseData);
  _selectedMCQ = result;
  notifyListeners();
}

}

MCQ类:

  late String mcqQuestionId;
  late String moduleId;
  late String mcqId;
  late String type;
  late String step;
  late int questionNumber;
  late String questionTitle;
  late String status;
  late List<MCQAnswer> mcqAnswerList;

  MCQ({
    required this.mcqQuestionId,
    required this.moduleId,
    required this.mcqId,
    required this.type,
    required this.step,
    required this.questionNumber,
    required this.questionTitle,
    required this.status,
    required this.mcqAnswerList,
  });

  factory MCQ.fromJson(dynamic json) {
    var mcqAnswerList = json[0]['QuestionList'] as List;
    List<MCQAnswer> loadedAnswerList =
        mcqAnswerList.map((e) => MCQAnswer.fromJson(e)).toList();
    return MCQ(
      mcqQuestionId: json[0]['_id'].toString(),
      moduleId: json[0]['moduleID'],
      mcqId: json[0]['mcqID'],
      type: json[0]['type'],
      step: json[0]['step'],
      questionNumber: json[0]['no'],
      questionTitle: json[0]['questionTitle'],
      status: json[0]['status'],
      mcqAnswerList: loadedAnswerList,
    );
  }
}

问题的视频。

4

0 回答 0