I’m new to Flutter and trying my best to write a function "getUserPictures" which should return a List of Pictures which are either saved locally on the device or fetched from Google Firebase.
The plan is to use that returned Future from this function later inside a Futurebuilder.
Every function which is called inside this function is tested and works properly.
The problem is, this function always returns null. I don’t understand why.
In this particular case i filled fetchOnline with false – and i know that there is a file called userPictures.json. So it should be found. The function should execute the code inside the if-block. And it does so, the file is even printed completely, but still, the functions returns null. Why?
I’m afraid i messed up the Future-related stuff. I hope you guys can help me..
These are the printed logs:
I/flutter (13977): Log: true
I/flutter (13977): Log: reading file userPictures.json
I/flutter (13977): Log: returning this null
I/flutter (29229): Log: read successful -> [Instance of ‘Picture’, Instance of ‘Picture’, Instance of ‘Picture’, Instance of ‘Picture’, Instance of ‘Picture’]
if u r using
await then there is no need to using
final jsonData = await CustomCache.readText(filename: "userPictures.json"); tempList = PixenseFunctions.convertJsonToListOfPictures(jsonData: jsonData);
Answered By – GJJ2019
Answer Checked By – Timothy Miller (FlutterFixes Admin)