I am trying to upload image from the Assets folder image but getting an error while trying to map the list of image. I have created CarouselModel
and trying to map. Error as The body might complete normally, causing 'null' to be returned, but the return type, 'List<T>', is a potentially non-nullable type.
How can It be solved? Thank you in advance.
class model :
class CarouselModel {
String image;
CarouselModel(this.image); }
List<CarouselModel> carsouels =
carsouelsData.map((item) => CarouselModel(item['image']!)).toList();
var carsouelsData = [
{"image": "images/pic1.jpg"},
{"image": "images/pic2.png"},
{"image": "images/pic3.jpg"},
];
Trying to map using:
List<T> map<T>(List list, Function handler) {
List<T> result = [];
for (var i = 0; i < list.length; i ) {
result.add(handler(i, list[i]));
}
}
View code:
body: Container(
child: ListView(
physics: ClampingScrollPhysics(),
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 16, right: 16),
child: Text(
'welcome to the beautiful world