Search code examples
fluttermodelcarouseldart-null-safety

The argument type 'String?' can't be assigned to the parameter type 'String'. in carousel image flutter model -


I'm gettin stuck in put my image carousel from model carousel_model.dart enter image description here

enter image description here//i.sstatic.net/Qp92R.png


Solution

  • Your CarouselModel's image variable data type is String. But reading a map can provide null data for unknown keys(the keys arent include on map).

    You can provide default value on null case or do a null check then add into list.

    Providing default empty string on null case.

    => CarouselModel(item['image']??"")).toList()
    

    If item is nullable do item?['image']??""