Reputation: 15
try to use data from api with http package but i get null safty problem the method '[]' cant be unconditionally invoked because the receiver can be 'null
return ListTile(
leading: CircleAvatar(backgroundImage: NetworkImage(snapShot.data[index]['thumbnailUrl']),),
title: Text(snapShot.data[index]['title']),
subtitle: Text("${snapShot.data[index]['id']}"),
);
Upvotes: 1
Views: 51
Reputation: 552
You need to tell dart that the variable is not null (only for the first time), this can be done by the use of !
after the variable, for instance if the error tells that snapShot.data
maybe null, type snapShot.data!
another example could be snapShot.data[index]['id']!
Upvotes: 1