Issue
I have such a code. But I am getting error.
_CastError (type 'Null' is not a subtype of type 'List<String?>' in type cast)
Codes:
Future<List<String?>> listUpload() async {
final prefences = await SharedPreferences.getInstance();
final getTests = prefences.getStringList("tests"); // get item
return Future.value(getTests);
}
How can I solve it?
Solution
The listUpload
can possibly return Null
depending on the situation. But you have specified a return type of Future<List<String?>>
.
To make it work try a return type dynamic
(not preferred) or check for null
before returning a value.
dynamic listUpload() async {
final prefences = await SharedPreferences.getInstance();
final getTests = prefences.getStringList("tests"); // get item
return Future.value(getTests);
}
Answered By - Mahan Marwat
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.