Flutter dart错误,预期的值类型为'List< Object>',但得到的值类型为'List< dynamic>'

8aqjt8rx  于 2022-12-14  发布在  Flutter
关注(0)|答案(1)|浏览(122)

我有一个C级像:

class C {
  int? first;
  int? second;
  C({
    this.first,
    this.second,
  });
}

我有两个类,其中一个从另一个扩展而来

class A {
  int? id;
  List<C>? list;
  A({
    this.id,
    this.list,
  });
}

class B extends A{
  String? title;
  B({
    this.title,
    list,
  ):super(
    list: list,
  );
}

在我腕尺中,我创建了如下B类的示例,但我得到了以下错误:

B b = B(title: '', list: []);

expected value of Type List<C> but got one of type List<dynamic>

我问题在哪里?

3pmvbmvn

3pmvbmvn1#

B类中,当扩展A时,需要定义list的类型:

class B extends A {
  String? title;
  B({
    this.title,
    List<C>? list,// change to this
  }) : super(
          list: list,
        );
}

相关问题