错误:I/flutter(5919):══╡ 小部件库发现异常╞═════════════════════════␕════════════ ═══════════════════════════ I/flutter(5919):在构建构建器时抛出了以下断言:I/flutter(5919):BlocProvider .of() 使用不包含 Bloc 类型的 Bloc 的上下文调用。I/flutter (5919):从传递给 I/flutter (5919) 的上下文开始找不到祖先:BlocProvider.of>()。我/颤振(5919):
如果您使用的上下文来自 BlocProvider 上方的小部件,则可能会发生这种情况。I/flutter (5919): 使用的上下文是: BlocBuilder, dynamic>(dirty, state: I/flutter (5919): _BlocBuilderBaseState, dynamic>#55a7d(lifecycle state: created)) I/flutter (5919): 相关导致错误的小部件是:I/flutter(5919):MaterialApp /lib/main.dart:35:12
这是我的主要内容
void main() {
final StorageRepository storageRepository = StorageRepository();
final AuthenticationRepository authenticationRepository =
AuthenticationRepository();
runApp(BlocProvider<AuthenticationBloc>(
create: (_) => AuthenticationBloc(
authenticationRepository: authenticationRepository,
storageRepository: storageRepository),
child: MyApp()));
}
MaterialApp 小部件
MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.deepPurple),
home: BlocBuilder(
builder: (context, state) {
print(state);
if (state is Authenticated) {
return MainPage();
} else if (state is Unauthenticated) {
return LoginPage();
} else if (state is Uninitialized) {
return SplashScreen();
}
return Container();
},
),