'Firestore security rules - Permission Denied in Flutter

I was trying to implement the security rules for my Firestore project. This statement here isn't working, can anyone tell me why? I am clueless at this point.

What I am trying to read and write from Database. I even tried rules without security, but still it generates Permission_DENIED.


    rules_version = '2';
    service cloud.firestore {
      match /databases/{database}/documents {
        match /{document=**} {
           allow read, write : if true;
        }
      }
    } 

Here is a code example from my app to access the users list.


    QuerySnapshot result = await FirebaseFirestore.instance
            .collection(FirestoreConstants.pathUserCollection)
            .where(FirestoreConstants.id, isEqualTo: peerId)
            .get();


    [Firestore]: Listen for Query(target=Query(users where id == u2trgq5zE3dZRUZgjkb8Ah9Aa533 order by __name__);limitType=LIMIT_TO_FIRST) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
    E/flutter ( 4357): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: [cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.
    E/flutter ( 4357): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
    E/flutter ( 4357): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
    E/flutter ( 4357): <asynchronous suspension>
    E/flutter ( 4357): #2      MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:367:43)
    E/flutter ( 4357): <asynchronous suspension>
    E/flutter ( 4357): #3      MethodChannelQuery.get (package:cloud_firestore_platform_interface/src/method_channel/method_channel_query.dart:97:42)
    E/flutter ( 4357): <asynchronous suspension>
    E/flutter ( 4357): #4      _JsonQuery.get (package:cloud_firestore/src/query.dart:390:9)
    E/flutter ( 4357): <asynchronous suspension>
    E/flutter ( 4357): #5      _LandingPageState.demo (package:favi_chat/screens/landing_screen.dart:30:34)
    E/flutter ( 4357): <asynchronous suspension>
    E/flutter ( 4357): 
    W/Firestore( 4357): (24.1.0) [WatchStream]: (eb84a9d) Stream closed with status: Status{code=CANCELLED, description=Disconnecting idle stream. Timed out waiting for new targets., cause=null}.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source