RuslanBek
RuslanBek

Reputation: 2009

Flutter firebase error Receiver: "Closure: () => Map<String, dynamic> from Function 'data':"

Recently I have upgraded my flutter to 2.0 and firebase packages to latest ones. After upgrading them i have refactored my deprecated firebase code to new one. In one of my functions i have got run-time error on cloud_firestore package.

Old one:

  Future popularSearch() async {
    final snapshot = await FirebaseFirestore.instance.collection('searches').getDocuments();
    final List<PopularSearch> loadedResult = [];

    snapshot.documents.forEach(
        (element) => loadedResult.add(PopularSearch.fromJson(element.data)));
    popularSearches = loadedResult;
    notifyListeners();
  }
}

New one:

  Future popularSearch() async {
    final snapshot = await FirebaseFirestore.instance.collection('searches').get();
    final List<PopularSearch> loadedResult = [];

    snapshot.docs.forEach(
        (element) => loadedResult.add(PopularSearch.fromJson(element.data)));
    popularSearches = loadedResult;
    notifyListeners();
  }

Now it is giving this error instead of fetching data:

E/flutter (12403): Receiver: Closure: () => Map<String, dynamic> from Function 'data':.
E/flutter (12403): Tried calling: []("query")
E/flutter (12403): Found: []() => Map<String, dynamic>

Upvotes: 0

Views: 929

Answers (1)

Ibrahim Ali
Ibrahim Ali

Reputation: 2503

Add a close bracket to element.data ===> element.data()

Upvotes: 2

Related Questions