flutter - 在启动画面中处理多个块并在主屏幕中显示结果
问题描述
我是 Flutter 的新手,我正在尝试在我的项目中实现 blocs。我需要帮助来实施多个集团。
情况如下:
main.dart:一旦应用程序启动,它将重定向到启动屏幕(使用自动路由包)
return MultiBlocProvider(
providers: [
BlocProvider(
create: (context) =>
getIt<AuthBloc>()..add(const AuthEvent.authCheckRequested()),
),
BlocProvider<PostWatcherBloc>(
create: (context) => getIt<PostWatcherBloc>()
..add(PostWatcherEvent.watchPost()),
),
BlocProvider<FeaturedWatcherBloc>(
create: (context) => getIt<FeaturedWatcherBloc>()
..add(FeaturedWatcherEvent.watchFeatured()),
),
BlocProvider<CategoryWatcherBloc>(
create: (context) => getIt<CategoryWatcherBloc>()
..add(CategoryWatcherEvent.watchCategories()),
),
],
child: MaterialApp.router(
title: Constants.appName,
debugShowCheckedModeBanner: false,
),
routerDelegate: _appRouter.delegate(),
routeInformationParser: _appRouter.defaultRouteParser(),
),
splash_page.dart:
return MultiBlocListener(
listeners: [
BlocListener<AuthBloc, AuthState>(listener: (context, state) {
state.map(
initial: (_) {},
authenticated: (_) => {
print("Authenticated"),
AutoRouter.of(context).push(HomePageRoute())
},
unauthenticated: (_) => {
print("Unauthenticated"),
AutoRouter.of(context).push(HomePageRoute())
});
}),
],
child: const Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
),
);
我的目标是一旦 Post/Category/FeaturedWatcherBloc 和 AuthBloc 被调用,它们的状态将被传递到 HomePage。基本上,一旦启动屏幕加载完成,主页上的帖子、精选和类别以及用户是否已登录都会准备好。
解决方案
推荐阅读
- c++ - 我们可以在 c++ 中分配我们想要的任意数量的字节吗?(例如为一个类型分配 6 个字节)
- android - 无法接受 Android 许可证,运行颤振医生命令后无法输入 Y/N(颤振)
- php - 使用 php 函数在 json 文件中添加和更新数据
- java - 在按钮单击时切换 BottomNavigationDrawer 片段
- javascript - 使用选择选择器单击后如何隐藏选择选项?
- android - 在 kotlin 序列化中是否可以不使用中间选项来立即转换 Map
到模型 - api - 如何通过 Notion API 访问页面历史(页面更新)
- python - 读取图像时 Google colab 中的 FileNotFound 错误
- bash - 如何从我的数据集中采样 50 个随机文件,每个文件在 shell 脚本中具有相同的概率?
- c++ - While 循环在插入排序中完美运行,但 For 循环没有按预期工作,而不是 while 循环