Flutter 颤振–;MultiBlocProvider不';t实例化集团
所以我有这个密码Flutter 颤振–;MultiBlocProvider不';t实例化集团,flutter,dart,flutter-bloc,Flutter,Dart,Flutter Bloc,所以我有这个密码 @override Widget build(BuildContext context) { return MultiBlocProvider( providers: [ BlocProvider<ProfilePageBloc>( create: (context) => ProfilePageBloc(userRepository: UserRepository.instance), ), B
@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"),
);
},
),
);
},
),
);
}
我希望profileBloc
像homeBloc
was一样被实例化
这使我完全无法继续发展。我不知道为什么会这样。
最好的是,它工作了几次,但我无法复制这种行为
任何帮助都将不胜感激事实证明,“ProfilePageBloc”没有实例化,因为断言在其构造函数中失败。 我在问题中提供的代码不足以解决它
homeBloc: Instance of 'HomeBloc'
profileBloc: null