我在firestore中有一个登录页和一个集合,我在其中保存了一些关于用户的信息(例如,他是否通过了登机屏幕(。下次我打开应用程序时,我想检查用户是否通过了登录。如果他们这样做了:我重定向到另一个屏幕;如果没有,则重定向到入职。
所有的例子都是阅读一个集合并获取所有文档,但我只需要阅读一个我知道documentid的文档。
我试过这样获取数据,但没有成功。
class LandingPage extends StatelessWidget {
// LandingPage({@required this.auth});
// final AuthBase auth;
@override
Widget build(BuildContext context) {
final auth = Provider.of<AuthBase>(context, listen: false);
return StreamBuilder<User>(
stream: auth.onAuthStateChanged,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.active) {
User user = snapshot.data;
if (user == null) {
return ChooseLanguage(
// auth: auth,
);
}
// he i need to do a call to a ducment in the firestore
//if the retuen is true then i go to page 1 else go to page 2
} else {
return Scaffold(
body: Center(child: CircularProgressIndicator()),
);
}
},
);
}
}
我必须做什么-iama初学者在颤振
要获得一个文档,请执行以下操作:
getData()async{
await Firestore.instance.collection("users").document(id).get().then((value){
print(value.data['name']);
});
}
您需要使用正确的collection
名称,value.data
将包含您可以使用[]
运算符访问的文档的数据。
根据您的编辑,您正在检查checkonboarding()
是否为null,但由于它返回了一个future,因此您需要使用wait:
void sendData()async{
bool value = await checkonBoarding(user);
if (value != null) {
return Provider<Database>(
create: (_) => new FireStoreDatabase(uid: user.uid),
child: Dashboard(usr: user, auth: auth),
);
} else {
return Provider<Database>(
create: (_) => new FireStoreDatabase(uid: user.uid),
child: Onboarding(usr: user, auth: auth),
);
}
}