所以我有这个代码
@override
Widget build(BuildContext context) {
return MultiBlocProvider(
providers: [
BlocProvider<ProfilePageBloc>(
create: (context) => ProfilePageBloc(userRepository: UserRepository.instance),
),
BlocProvider<HomeBloc>(
create: (context) => HomeBloc(),
),
],
child: BlocBuilder<HomeBloc, HomeState>(
builder: (context, state) {
return Scaffold(
body: BlocBuilder<HomeBloc, HomeState>(
builder: (context, state) {
if (state is StateThatDoesNotMatter) {
final HomeBloc homeBloc = BlocProvider.of<HomeBloc>(context);
final ProfilePageBloc profileBloc = BlocProvider.of<ProfilePageBloc>(context);
print("homeBloc: ${homeBloc.toString()}");
print("profileBloc: ${profileBloc.toString()}");
return Center(
child: Text("Doesn't really matter"),
);
},
),
);
},
),
);
}
我得到的输出是
homeBloc: Instance of 'HomeBloc'
profileBloc: null
我希望profileBloc
像以前那样被实例化homeBloc
。
这让我完全无法继续开发。我不知道为什么会这样。最好的是,它工作了几次,但我无法重现这种行为。
任何帮助将不胜感激