参数类型“List<dynamic>”不能分配给参数类型“List<QuestionCategory>”

问题描述 投票:0回答:1

我在我的第一个应用程序上遇到此错误,但第二个应用程序使用相同的代码可以正常工作。

测验模型文件:

class QuizModel {
  String question;
  List<String> correctAnswers;
  List<String> options;
  String? yourAnswer;
  String? info;
  String? desc;
  String? topic;

  QuizModel({
    required this.question,
    required this.correctAnswers,
    required this.options,
    this.yourAnswer,
    this.info,
    this.desc,
    this.topic,
  });
}

问题模型文件:

class QuestionCategory {
  final String question;
  final String correctAnswer;
  final List<String>? wrongAnswer;
  final String? info;
  final String? desc;
  final bool? isQuiz;
  final String? topic;
  bool isExpanded = false;
  String? yourAnswer;
  List<String>? shuffledOptions;

  QuestionCategory({
    required this.question,
    required this.correctAnswer,
    this.wrongAnswer,
    this.info,
    this.desc,
    this.isQuiz,
    this.topic,
  });
}

我这样使用它:

class QuizList {
  static List<QuestionCategory> oct2024Quiz = [
    QuestionCategory(
      question: 'Where was the India Digital Agri Conference 2024 organized?',
      correctAnswer: '4',
      wrongAnswer: ['1', '2', '3'],
      info: "4 is bigger then all",
      desc: "NA",
    ),
  ];
}

请针对上述问题提出一些解决方案。

dart
1个回答
0
投票

提供的模型似乎是正确的,可疑的代码部分显然是一个赋值操作,您将

List<dynamic>
分配给
List<QuestionCategory>
但您没有在提供的代码中

因此,重新检查整个代码以找出哪一行产生此错误(可能是另一个赋值操作)。

© www.soinside.com 2019 - 2024. All rights reserved.