flutter Firestore访问被拒绝

1l5u6lss  于 2023-08-07  发布在  Flutter
关注(0)|答案(1)|浏览(94)

带Firestore(21122):(24.7.0)[WatchStream]:(6db 20 e0)流已关闭,状态为:状态{code=PERMISSION_DENIED,description=资源项目resturant的权限被拒绝。原因=null}。
每当我运行flutter应用程序时,它会在控制台中显示这条消息,而且它不会从数据库中获取任何数据。

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;
    }
  }
}

字符串
我试过了,但是没有用。

class ard extends StatefulWidget{
  @override
  State<ard> createState() => _ardState();
}

class _ardState extends State<ard> {
  final Cartcontroller = Get.put(cartcontrol());

  final _productstream = FirebaseFirestore.instance.collection('products').snapshots();

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return
      Scaffold(
          appBar: AppBar(centerTitle: true,leading:IconButton(
            onPressed: () => Navigator.push(context, MaterialPageRoute(builder:(BuildContext context)=>Loginform()))
            ,icon: Icon(Icons.person),tooltip:"Login" ,),

            title: Text('Al Baik'),backgroundColor: Colors.red,automaticallyImplyLeading: false,
          ),
            floatingActionButton: FloatingActionButton(backgroundColor: Colors.red,
              onPressed: () {
                Cartcontroller.Total();
              },child: Icon(Icons.shopping_cart),
            ),
            body:
            Scaffold(appBar: AppBar(backgroundColor: Colors.white54,toolbarHeight: 30,
              leading: ListView(
                scrollDirection: Axis.horizontal,
                children: [
                  ElevatedButton.icon(onPressed: () {},icon:Icon(Icons.local_drink_rounded) ,
                      style:ElevatedButton.styleFrom(fixedSize: Size.fromWidth(55.0),backgroundColor: Colors.white10 ,
                      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30))
                      ),
                      label: Text(""),),
                ],
              ),
            ),
              body:
              StreamBuilder(
                stream: _productstream,
                builder: (context, snapshot) {
                  if (snapshot.hasError) {
                    return const Text('connection error');
                  }
                  if (snapshot.connectionState == ConnectionState.waiting) {
                    return const Text("Loading");
                  }
                  var Docs = snapshot.data!.docs;
                  return ListView.builder(
                    itemCount: Docs.length,
                      itemBuilder: (BuildContext context,int index) {
                      return Text(Docs[index]['name']);
                      }
                  );
                }
              )
               ),
    );
  }
}


这是我的密码

o7jaxewo

o7jaxewo1#

您需要在allow规则后面有一个布尔值true以允许访问,用:分隔。试试这个:

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

字符串

相关问题