【发布时间】:2021-07-24 18:24:00
【问题描述】:
我是新来的颤振并试图让它发挥作用。我有一个 Welcome() 页面,它有两个按钮(SignUp 和 SignIn),它们会将您带到 SignUp() 和 SignIn() 页面。成功验证后,应用程序应该导航到 Home(),但它没有。如果用户注销,它也不会返回 Welcome() 页面。此外,如果应用程序已启动并且用户已经登录,它不会自动转到 Home(),它会停留在 Welcome()。我在这里做错了什么? 我正在使用这样的 StreamProvider
if (snapshot.connectionState == ConnectionState.done) {
return StreamProvider<User>.value(
value: AuthService().user, child: Wrapper());
}
我的包装看起来像这样:
class Wrapper extends StatelessWidget {
const Wrapper({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
final user = Provider.of<User>(context);
if (user != null)
print(user.id);
else
print("User is null");
return MaterialApp(initialRoute: '/', routes: {
'/': (context) => user == null ? Welcome() : Home(),
'/signup': (context) => SignUp(),
'/signin': (context) => SignIn()
'/profile': (context) => Profile(),
'/edit': (context) => Edit()
});
}
这会打印用户 ID,这意味着用户不为空,但它不会导航到 Home()。
【问题讨论】:
标签: flutter