繁体   English   中英

没有为 Flutter Firebase 中的“QuerySnapshot”类型错误定义吸气剂“文档”

[英]The getter 'documents' isn't defined for the type 'QuerySnapshot' error in Flutter Firebase

所以我想在 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()));
          }
        }
      });
    });
  }
}

尝试这个。 但我建议您用于角色管理访问始终使用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()));
          }
   }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM