所以我最近在我的应用程序中切换到 Go router,因为它非常容易实现。但我在从启动屏幕转移到登录屏幕时遇到问题。我的启动屏幕中有逻辑,我可以检查用户是否登录。根据用户的身份验证,屏幕将转到登录屏幕或主页。
这是启动画面。
class SplashScreen extends StatefulWidget {
static const routeName = "/SplashScreen";
const SplashScreen({Key? key}) : super(key: key);
@override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen>
with SingleTickerProviderStateMixin {
@override
Widget build(BuildContext context) {
return BlocConsumer<AuthenticationBloc, AuthenticationState>(
listener: (context, state) {
if (kDebugMode) {
print('Listener: $state');
}
Future.delayed(const Duration(seconds: 3), () {
if (state.authStatus == AuthStatus.unAuthenticated) {
GoRouter.of(context).go('/login');
Navigator.pushNamed(context, SignUpScreen.routeName);
} else if (state.authStatus == AuthStatus.authenticated) {
//Navigator.popUntil(context, (route) => route.isFirst);
Navigator.pushReplacementNamed(context, HomePage.routeName);
}
});
}, …Run Code Online (Sandbox Code Playgroud)