Flutter显示基于FireStore数据字段的单独页面



我有一个基本的应用程序,我使用电子邮件登录和注册来登录该应用程序。我使用提供者,并根据用户的当前状态推送至登录页面或主页。

当用户登录时,我想将他重定向到一个新屏幕(信息页面(,在那里他必须填写一些其他数据,这些数据将作为他的UID保存在Firestore中的一个文档下。(这些额外的数据只是地址/姓名/电话..bla bla(

但是,如果用户注销并再次登录,他不应该被重定向到信息页面,因为他已经提交了数据。

如果用户没有将数据提交到信息页面,我如何重定向他?如果他提交了数据,我如何将他发送到主页?

这是我的代码与提供商和家庭控制器

@override
Widget build(BuildContext context) {
return Provider(
auth: AuthService(),
db: FirebaseFirestore.instance,
child: MaterialApp(
theme: ThemeData(
primaryColor: Colors.lightGreen[300],
primaryColorDark: Colors.amber,
errorColor: Colors.amber,
hintColor: Colors.grey
),
title: "Farmline.LK",
home: HomeController(),
routes: <String, WidgetBuilder>{
'/home': (BuildContext context) => HomeController(),
'/signUp': (BuildContext context) => FirstView(),
}),
);
}
}
class HomeController extends StatelessWidget {
@override
Widget build(BuildContext context) {
final AuthService auth = Provider.of(context).auth;
return StreamBuilder<String>(
stream: auth.onAuthStateChanged,
builder: (context, AsyncSnapshot<String> snapshot) {
if (snapshot.connectionState == ConnectionState.active) {
final bool signedIn = snapshot.hasData;
return signedIn ? Home() : FirstView();
}
return Container();
},
);
}
}

非常感谢您的支持!

将当前逻辑扩展到以下内容:

return StreamBuilder<String>(
stream: auth.onAuthStateChanged,
builder: (context, AsyncSnapshot<String> snapshot) {
if (snapshot.connectionState == ConnectionState.active) {
if (snahpshot.hasData) {
var user = snapshot.data;
if (user.name == null || user.phone == null ...) {
return FirstView();
} 
return Home();
}
return Container();
}
},
);

最新更新