【发布时间】:2020-05-20 00:18:32
【问题描述】:
错误:I/flutter (5919):══╡ 小部件库发现异常 ╞═════════════════════════════════════════════════ ══════════ I/颤振 (5919):在构建 Builder 时抛出了以下断言: I/flutter(5919):使用上下文调用 BlocProvider.of() 不包含 Bloc 类型的 Bloc。 I/flutter(5919):找不到祖先 从传递给 I/flutter ( 5919) 的上下文开始: BlocProvider.of>()。我/颤振(5919):
如果您使用的上下文来自 块提供者。 I/flutter(5919):使用的上下文是: BlocBuilder,动态>(脏,状态:I/flutter( 第5919章 dynamic>#55a7d(lifecycle state: created)) I/flutter (5919): The 相关的导致错误的小部件是: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();
},
),
【问题讨论】:
标签: flutter bloc flutter-bloc