【问题标题】:The getter 'documents' isn't defined for the type 'QuerySnapshot' error in Flutter Firebase没有为 Flutter Firebase 中的“QuerySnapshot”类型错误定义吸气剂“文档”
【发布时间】:2022-01-10 15:50:43
【问题描述】:

所以我想在 Flutter 中对我的应用实施基于角色的身份验证。只有具有权限的用户才能访问此站点。我得到了错误:

The getter 'documents' isn't defined for the type 'QuerySnapshot<Map<String, dynamic>>'.
Try importing the library that defines 'documents', correcting the name to the name of an existing getter, or defining a getter or field named 'documents'.

有人可以帮我吗?

代码:

class AutoLoginHandler extends StatelessWidget {
  @override
  authorizeAccess(BuildContext context) {
    FirebaseAuth.instance.currentUser!().then((user) {
      FirebaseFirestore.instance
          .collection('/users')
          .where('uid', isEqualTo: user.uid)
          .get()
          .then((docs) {
        if (docs.documents[0].data.exists) {
          if (docs.documents[0].data['role'] == 'admin') {
            Navigator.of(context).push(new MaterialPageRoute(
                builder: (BuildContext context) => new LehrerMainPage()));
          }
        }
      });
    });
  }
}

【问题讨论】:

    标签: android firebase flutter google-cloud-firestore


    【解决方案1】:

    试试这个。但我建议你使用角色管理访问总是使用Custom Claims。

    .then((results) {
       if (results.size > 0) {
              if (results.docs[0].data()['role'] == 'admin') 
             {
                Navigator.of(context).push(new 
       MaterialPageRoute(
                    builder: (BuildContext context) => new 
       LehrerMainPage()));
              }
       }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-22
      • 2021-02-27
      • 1970-01-01
      • 1970-01-01
      • 2021-04-14
      • 2021-09-17
      • 2021-03-04
      • 2021-11-12
      相关资源
      最近更新 更多