Home > Software design >  The argument type 'String?' can't be assigned to the parameter type 'String'
The argument type 'String?' can't be assigned to the parameter type 'String'

Time:09-14

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

enter image description here//i.stack.imgur.com/Qp92R.png

CodePudding user response:

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']??""

  • Related