我已将与提供程序连接的授权逻辑添加到我的应用程序中,一切正常,直到测试“注册”按钮。 首先,我需要提到 signIn 和 signUp 是相同的功能。 其次,点击signIn后视图刷新(立即进入BottomNavigator屏幕),所以功能写得很好。 第三,在点击注册然后返回到最后一个屏幕应用程序正在呈现底部导航屏幕。
那么问题出在哪里呢?有人可以解释一下我的行为吗?
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider.value(
value: Auth(),
)
],
child: Consumer<Auth>(
builder: (context, auth, _) {
return MaterialApp(
title: 'x',
theme: CustomTheme.lightTheme,
home: auth.isAuth
? BottomNavigation()
: FutureBuilder(
future: auth.tryAutoLogin(),
builder: (context, authResultSnapshot) =>
authResultSnapshot.connectionState ==
ConnectionState.waiting
? SplashScreen()
: SignIn(),
),
routes: Routes.getRoutes(),
);
},
),
);
}
}
class SignIn extends StatefulWidget {
@override
_SignInState createState() => _SignInState();
}
class _SignInState extends State<SignIn> {
void _signIn() {
Provider.of<Auth>(context, listen: false).signIn();
}
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
OutlinedButton(
onPressed: () => _signIn(),
child: Text("signIn"),
),
OutlinedButton(
onPressed: () => Navigator.pushNamed(context, Routes.signUp),
child: Text("go to sign up"),
),
],
);
}
}
class SignUp extends StatefulWidget {
@override
_SignUpState createState() => _SignUpState();
}
class _SignUpState extends State<SignUp> {
void _signUp() {
Provider.of<Auth>(context, listen: false).signUp();
}
@override
Widget build(BuildContext context) {
return Center(
child: OutlinedButton(
onPressed: () => _signUp(),
child: Text("SignUp"),
),
);
}
}