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?
CodePudding user response:
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);
}