-1

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']

enter image description here

Arveni
  • 68
  • 6

1 Answers1

1

if u r using async & await then there is no need to using then callback

final jsonData = await CustomCache.readText(filename: "userPictures.json");
tempList = PixenseFunctions.convertJsonToListOfPictures(jsonData: jsonData);
GJJ2019
  • 4,624
  • 3
  • 12
  • 22
  • Wow! Thanks, it did work. So it's not allowed to use `.then` in combination with async&await? – Arveni Nov 22 '20 at 03:55
  • most welcome u can use but u need to be sure of its execution in current flow kindly mark & upvote the answer – GJJ2019 Nov 22 '20 at 05:26