skip to Main Content

I am trying to get the data from "savedGoal" collection and somehow it is throwing error (NoSuchMethodError). However same script/syntax of code is working absolutely fine for another collection on same firebase project. Please let me know what could be wrong here. Here is the script that I am running in ininState()-

FirebaseFirestore.instance
        .collection("savedGoals")
        .where('uid', isEqualTo: FirebaseAuth.instance.currentUser.uid)
        .get()
        .then((value) {
      value.docs.forEach((result) async {
        if (result.data().isNotEmpty) {
          setState(() {
            goalAmount = result.data()['goalAmountFixed'];
          });
        }

Here is the screenshot of error that I am receiving while using "savedGoal" collection –
enter image description here

Here is the firebase document screenshot-
enter image description here

2

Answers


  1. Check main.dart to ensure that you have initialized Firebase correctly. In case you have not initialized Firebase in your project then try initializing it by adding this in main:

    main() async {
        await Firebase.initializeApp(
          options: DefaultFirebaseOptions.currentPlatform,
        );
    }
    

    If that’s not the case then can you please send add the logs related to this issue. Also cross check the format of the code. Use results.isNotEmpty() instead of results().data.isNotEmpity().

    Login or Signup to reply.
  2. Then probably because .where('uid', isEqualTo: FirebaseAuth.instance.currentUser.uid) returning null because no matching documents are available.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search