skip to Main Content

I have a error "A value of type ‘OutletListModel’ can’t be assigned to a variable of type ‘List?’"

so how to resolve this error

List<OutletListModel>? selectedData;

enter image description here

3

Answers


  1. You can add item on list with myList.add(YouItem). if you like to replace , you can do myList = [.... ], but in this case myList shouldn’t be final.

    For your case, you can do

    final newItem  = OutletModel.from(.....);
    selectedData.add(newItem);
    
    Login or Signup to reply.
  2. change the code line where the error appears with:

    selectedData = [OutletListModel.fromJson(value.toJson())];
    

    because selectedData expects an Array of OutletListModel;

    Login or Signup to reply.
  3. OutletListModel.fromjson(value.tojson()).tolist()
    

    make the response as list to assign

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search