【发布时间】:2020-12-28 10:54:30
【问题描述】:
我想根据用户类型显示 3 种类型的页面 - 客户类型的“MyPage”,专业人士类型的“MyPagePro”和新用户打开应用程序时的“Choice”类型。但是,我的以下代码在“snapshot.document”部分显示错误。我不知道应该纠正什么。请帮忙。
class Wrapper extends StatelessWidget {
@override
Widget build(BuildContext context) {
final user = Provider.of<User>(context);
Future snapshot = Firestore.instance
.collection('crews')
.document(user.uid)
.collection('pros')
.getDocuments();
if (user == null) {
return Choice();
} else if (snapshot.documents.length == 0) {
return MyPage();
} else {
return MyPagePro();
}
}
}
我按照 'lenz' 的建议使用了 Future Builder,我的问题得到了解决,尽管在转到我想要的页面之前,红屏显示了几秒钟。谢谢,lenz!
class Wrapper extends StatelessWidget {
@override
Widget build(BuildContext context) {
final user = Provider.of<User>(context);
final uid = user.uid;
return FutureBuilder(
future: Firestore.instance
.collection('crews')
.document(user.uid)
.collection('pros')
.getDocuments(),
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
if (user == null) {
return Choice();
} else if (snapshot.documents.length == 0) {
return MyPage();
} else {
return MyPagePro();
}
});
【问题讨论】:
-
仍然没有写出当前代码的问题所在。上一个问题被关闭可能是因为您没有花时间写一个好的问题,但您希望有人花时间写一个好的答案。
-
我编辑了我的问题。我忘了写一个问题,现在我添加了。
-
我的回答有用吗?如果不让我知道
-
最好发布错误代码并避免使用“我在那儿遇到错误”的格式。完整的错误消息包含有助于您(和其他人)调试的特定信息(文件名、行号、潜在修复...)。添加完整的错误消息以帮助我们与您一起调试。
-
我发布了一个新代码,仍然有错误。
标签: flutter google-cloud-platform google-cloud-firestore