Flutter Bloc auth不会听(卡在Ongenerateroute)
IAM当前在Bloc上学习,我遵循此代码 https://github.com/felangel/bloc/tree/master/master/examples/flutter_login
但是,当IAM运行时,但是我陷入了Splashscreen,无法
使用粘贴垃圾箱穿过仪表板 /登录页IAM,因为我收到了警告,看起来您的帖子主要是代码;请添加更多详细信息。
mymain
class MyApp extends StatelessWidget {
final _navigatorKey = GlobalKey<NavigatorState>();
NavigatorState get _navigator => _navigatorKey.currentState!;
@override
Widget build(BuildContext context) {
final _authenticationRepository = AuthRepository();
return RepositoryProvider.value(
value: _authenticationRepository,
child: BlocProvider(
create: (_) => AuthBloc(authRepository: _authenticationRepository),
child: MaterialApp(
navigatorKey: _navigatorKey,
builder: (context, child) {
return BlocListener<AuthBloc, AuthState>(
listener: (context, state) {
switch (state.status) {
case AuthStatus.authenticated:
_navigator.pushAndRemoveUntil<void>(
DashBoard.route(),
(route) => false,
);
break;
case AuthStatus.unauthenticated:
_navigator.pushAndRemoveUntil<void>(
LoginPage.route(),
(route) => false,
);
break;
default:
_navigator.pushAndRemoveUntil<void>(
LoginPage.route(),
(route) => false,
);
break;
}
},
child: child,
);
},
onGenerateRoute: (_) => SplashScreen.route(),
)),
);
}
}
myauthbloc
https://pastebin.com/BQnhDeFE
myauthstate
https://pastebin.com/fmfnMwCV
myauthevent,
https://pastebin.com/tcEeqQsr
通过在飞溅屏幕上添加initstate并调用自动启动
@override
void initState() {
context.read<AuthBloc>().add(AuthInitial());
super.initState();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在存在存储库上的订阅:
authenticationRepository
触发拳头authenticationStatusChanged
事件,因为您是从Bloc库开始的,所以我建议您用 blocobserver :
如果事件在那里,它将简化学习过程和验证
You can notice in the example subscription on repository is present:
AuthenticationRepository
triggers the fistAuthenticationStatusChanged
eventSince you are starting with Bloc library i suggest you wrap your main with BlocObserver:
It will ease up the learning process and verification if events correct events are there