简体   繁体   English

我正在使用 firebase firestore (flutter) dart

[英]iam using firebase firestore (flutter) dart

i want to get user type field from firestore to route the user to either (Store owner page ) or (Customer page )?我想从 firestore 获取用户类型字段以将用户路由到(商店所有者页面)或(客户页面)? 消防站

I want to get the value to decide which page the user should see我想获取值来决定用户应该看到哪个页面

我试过这个功能,但没有用

you're trying to get the userType field directly from the DocumentSnapshot , which will return null , you need to get data of field from the Map<String, dynamic> which is returned from data() , so you need to change:您正在尝试直接从DocumentSnapshot获取userType字段,这将返回null ,您需要从Map<String, dynamic>获取字段数据,这是从data()返回的,因此您需要更改:

userType = documentSnapshot['userType'];

with this:有了这个:

userType = (documentSnapshot.data() as Map<String, dynamic>)['userType'];

this will save the value of userType field in the userType variable.这会将userType字段的值保存在userType变量中。

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

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