- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Error: I/flutter ( 5919): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ I/flutter ( 5919): The following assertion was thrown building Builder: I/flutter ( 5919): BlocProvider.of() called with a context that does not contain a Bloc of type Bloc. I/flutter ( 5919): No ancestor could be found starting from the context that was passed to I/flutter ( 5919): BlocProvider.of>(). I/flutter ( 5919):
This can happen if the context you used comes from a widget above the BlocProvider. I/flutter ( 5919): The context used was: BlocBuilder, dynamic>(dirty, state: I/flutter ( 5919): _BlocBuilderBaseState, dynamic>#55a7d(lifecycle state: created)) I/flutter ( 5919): The relevant error-causing widget was: 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(
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();
},
),
最佳答案
您忘记为 BlocBuilder 小部件提供 Bloc 和 State 类型
MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.deepPurple),
/// You need to specify the type here,
/// that's why you got error Bloc<dynamic, dynamic>
home: BlocBuilder<AuthenticationBloc, AuthenticationState>(
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 - BlocProvider.of() 使用不包含 Bloc<dynamic,dynamic> 类型的 Bloc 的上下文调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60052844/
我想了解惰性标志有什么影响。以及设置为true或false的考虑因素是什么? 最佳答案 当为真时,Bloc 或 Cubit 应该延迟创建,这意味着,直到第一次访问 Bloc 的请求(例如 contex
在我的应用程序中的一个类中,我想通过类参数传递 BlocProvider,例如: enum MenuItems{ dashboard, tutorials, logout } class
面临 BlocProviders 的问题。 据我了解,一个 block 应该可以在继承的小部件范围内的任何地方访问。 我有一个 App 类,它恰好是我的核心类,我在其中构建我的 Material Ap
@override Widget build(BuildContext context) { return MultiBlocProvider( providers: [
我是 Flutter 的新手,最近开始学习 BLoC 模式。 我不明白为什么我需要在小部件内部使用 BlocProvider.of(context),我可以在所有小部件依赖的文件顶部简单地实例化一个
我有以下我正在尝试使用的通用 Bloc。 class ManageFeedbackBloc extends Bloc {} 我使用以下提供程序来创建它: void _navigateToContrib
我正在尝试找到一种方法来创建一个新的 bloc 实例并将其反射(reflect)在 multibloc 提供程序中。 目前我有以下内容: Scaffold( appBar: AppBa
我是 Flutter 的新手,我想使用 BLoc 实现一个简单的登录屏幕。没有构建错误,但在运行时收到以下错误 “使用不包含 LoginBloc 类型的 Bloc 的上下文调用 blocprovide
首先,我确实知道 BLoC 应该如何工作,它背后的想法和我知道 BlocProvider() 之间的区别和 BlocProvider.value()构造器。 为简单起见,我的应用程序有 3 个页面,其
有没有人知道我如何做到这一点? 我的代码: @override void dispose() { final FiltersBloc filtersBloc = Bloc
以下是来自的示例代码: https://bloclibrary.dev/#/flutterbloccoreconcepts 我收到以下异常, 如何修复以下异常以及为什么会发生这种情况: ═══════
我试图路由我的 TaharatPage,但我收到了这样的错误 The following assertion was thrown building TaharatGeneralPage(dirty)
我有一个位于主路线内的 MainBloc,该路线有一个带有多个子路线的底部应用程序栏,我希望相同的 BLoC 在所有五个子路线上运行,以便当其中一个子路线更改状态时该 block 其他人将看到效果。
我有一个位于主路线内的 MainBloc,该路线有一个带有多个子路线的底部应用程序栏,我希望相同的 BLoC 在所有五个子路线上运行,以便当其中一个子路线更改状态时该 block 其他人将看到效果。
在 flutter 中,我刚刚学习了如何在应用程序上使用 Bloc,我想尝试使用此功能实现简单的登录。在实现一些 bloc 类以在 View 中使用它之后 当我尝试将此代码用作 BlocProvide
我在我的 Flutter 应用程序中使用了 flutter_bloc 4.0.0,我使用了 Felix Angelov ( https://medium.com/flutter-community/f
构建方法内部: return BlocBuilder( bloc: UserCubit("firstName", "lastName"), builder: (BuildConte
Error: I/flutter ( 5919): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═════════════════════════════════
假设我在 BlocProviderTree 中有 3 个 BLoC,这意味着这些 bloc 可用于该类。其中一个用作 BlocListener,现在我希望将其他两个 BLoC 用作 BlocBuild
我是一名优秀的程序员,十分优秀!