Flutter中被拒绝的Firebase

时间:2019-02-19 21:03:48

标签: firebase flutter google-cloud-firestore

我试图使用Firebase应用程序中的文本,每个文本的每个Page View,但是它给了我拒绝权限的日志,我也尝试使用FutureBuilder,但是给出了同样的错误。

我的错误日志:

  

W / Firestore(28023):(0.6.6-dev)[Firestore]:侦听查询(teste)   失败:状态{code = PERMISSION_DENIED,描述=缺少或   权限不足。,cause = null}       I / System.out(28023):com.google.firebase.firestore.FirebaseFirestoreException:   PERMISSION_DENIED:缺少权限或权限不足。       W / Firestore(28023):(0.6.6-dev)[Firestore]:侦听查询(课程)失败:Status {code = PERMISSION_DENIED,   description =权限不足或权限不足。,cause = null}       I / System.out(28023):com.google.firebase.firestore.FirebaseFirestoreException:   PERMISSION_DENIED:缺少权限或权限不足。

代码:

    class LessonPage extends StatelessWidget {
  final LessonData lessonData;

  LessonPage(this.lessonData);

  @override
  Widget build(BuildContext context) {

    return StreamBuilder<QuerySnapshot>(
      stream: Firestore.instance.collection("lessons").snapshots(),
      builder: (context, snapshot) {
        if (snapshot.hasError) {
          return Center(
            child: Text(
              "An Has Error Occurred",
              style: TextStyle(color: Colors.red, fontSize: 24.0),
            ),
          );
        }
        switch (snapshot.connectionState) {
          case ConnectionState.waiting:
            return Center(
              child: CircularProgressIndicator(),
            );
          case ConnectionState.none:
            {
              return Center(
                child: Text(
                  "Without Connection!",
                  style: TextStyle(color: Colors.red, fontSize: 24.0),
                ),
              );
            }
          case ConnectionState.done:
          case ConnectionState.active:

          default:
          return PageView.builder(
            itemBuilder: (context, index) {
              return LessonWidget(
                  LessonData.fromDocument(snapshot.data.documents[index]));
            },
            itemCount: snapshot.data.documents.length,
          );
        }
      },
    );
  }
}

LessonWidget类(我正在从Firebase获取课程文本文档快照,并放入我的Text):

    class LessonWidget extends StatelessWidget {
  final LessonData lessonData;

  LessonWidget(this.lessonData);

  @override
  Widget build(BuildContext context) {

    return ListView(
      children: <Widget>[
        Text("${lessonData.text == null ? lessonData.text : "" }", style:
        TextStyle(color: Colors.black54, fontSize: 30.0),),
        SizedBox(height: 18.0,),
        TextField(
          decoration: InputDecoration(
              hintText: "Escreva a sua resposta aqui"
          ),
          autofocus: true,
        ),
        SizedBox(height: 10.0,),
        RaisedButton(onPressed: () {

        },
          color: Theme
              .of(context)
              .primaryColor,
          child: Text("Continuar"),)
      ],
    );

  }
}

1 个答案:

答案 0 :(得分:0)

PERMISSION_DENIED 错误是由于在 Firestore 上设置了 security rules。默认情况下,Firestore 上设置的规则要求用户进行访问身份验证。我建议重新访问您节点上设置的规则以解决此问题。