0
Future<List> getHistory() async {
List images;
final List<DocumentSnapshot> documents =
    (await Firestore.instance.collection("History").getDocuments()).documents;
images = documents.map((documentSnapshot) => documentSnapshot['images']).toList();
return images;
}

Hi all, what am I doing wrong here, it never returns images. I am sure that I am not doing this the correct way so any hints would be greatly appreciated.

class _HomeScreenState extends State<HomePage> {
   @override
  void initState() {
    super.initState();    
    getHistory();

  }

Thank you

1 Answers1

0

You're returning the images but not doing anything with the return value, Try this:

class _HomeScreenState extends State<HomePage> {
    List images;

    Future<List> getHistory() async {
    final List<DocumentSnapshot> documents =  (await 
    Firestore.instance.collection("History").getDocuments()).documents;
    images = documents.map((documentSnapshot) => documentSnapshot['images']).toList();
   }

   @override
  void initState() {
    super.initState();    
    getHistory();

  }

And in the widget tree use a future builder that awaits getHistory()'s results

barbecu
  • 684
  • 10
  • 28
  • Thank you, I am sorry but am new to Flutter and Im not sure how to implement "And in the widget tree use a future builder that awaits getHistory()'s results" I will hit google for material. – Jay Stewart Jun 20 '20 at 15:34
  • https://stackoverflow.com/questions/51983011/flutter-future-builder-when-should-i-use-it – barbecu Jun 21 '20 at 10:31