我有这样的代码:
MultiBlocProvider(
providers: [
BlocProvider(
create: (context) => CubitExample(),
),
],
child: MaterialApp(
home: Home(),
),
);
它工作得很好,我有很多块,所以我决定将提供者列表移到一个单独的类中:
MultiBlocProvider(
providers: BlocProviders.blocs(),
child: MaterialApp(
home: Home(),
),
);
// The class
class BlocProviders {
static List<BlocProvider> blocs() {
return <BlocProvider>[
BlocProvider(
create: (context) => CubitExample(()),
),
];
}
}
现在抛出常见的阻塞错误:
ProviderNotFoundException (Error: Could not find the correct Provider<ExampleCubit> above this BlocBuilder<ExampleCubit, ExampleState> Widget
我不知道为什么当我try 第二个代码时会抛出错误,为什么会抛出错误?