Home > Software design >  FLutter dart error expected value of Type 'List<Object>' but got one of type 'L
FLutter dart error expected value of Type 'List<Object>' but got one of type 'L

Time:12-15

I have a class C like :

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

and I have two classes that one of them extend from the other:

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,
  );
}

in my cubit I made instance of B class like below and I got this error :

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

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

where is my problem?

CodePudding user response:

In your B class you need to define the type for list when you extends A:

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