简体   繁体   English

错误:未为类型“Bloc”定义设置器“observer”<event, state> '</event,>

[英]error: The setter 'observer' isn't defined for the type 'Bloc<Event, State>'

I'm using flutter_bloc and according to this example I want to observe the bloc.我正在使用 flutter_bloc,根据这个例子,我想观察这个集团。 but I get this error:但我收到此错误:

error: The setter 'observer' isn't defined for the type 'Bloc<Event, State>'. (undefined_setter at [login_bloc_project] lib\main.dart:12)

when calling this method:调用此方法时:

void main() {
  Bloc.observer = MyBlocObserver();
  runApp(MyApp());
}

how can I fix this error?我该如何解决这个错误?

You can try like this:你可以这样尝试:

  BlocOverrides.runZoned(
    () => runApp(const MyApp()),
    blocObserver: MyBlocObserver(),
  );

Your package version might be lower than v8.1.0.您的软件包版本可能低于 v8.1.0。 BlocObserver is updated with that version. BlocObserver 已更新为该版本。 You can upgrade your dependency to solve this.你可以升级你的依赖来解决这个问题。

For more info: https://bloclibrary.dev/#/migration?id=v810更多信息: https ://bloclibrary.dev/#/migration?id=v810

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 BloC 测试“未为类型‘对象’定义方法 xxx”错误 - BloC testing "The method xxx isn't defined for the type 'Object'" error 未为“BuildContext”类型定义方法“bloc” - The method 'bloc' isn't defined for the type 'BuildContext' 没有为“JitsiMeetingOptions”类型定义设置器“featureFlag” - The setter 'featureFlag' isn't defined for the type 'JitsiMeetingOptions' 错误:没有为 class '_HomeState' 定义 setter 'pressed' - Error: The setter 'pressed' isn't defined for the class '_HomeState' 命名参数“bloc”未定义 - bloc 提供者 - The named parameter 'bloc' isn't defined - bloc provider 错误:没有为该类型定义方法“onChanged” - error: The method 'onChanged' isn't defined for the type 错误:未为类型“DocumentSnapshot”定义运算符“[]” - error: The operator '[]' isn't defined for the type 'DocumentSnapshot' : 错误: 没有为 class 'BlocBase 定义 getter 'ut'<state> '</state> - : Error: The getter 'ut' isn't defined for the class 'BlocBase<State>' Bloc 错误 apiState 数据加载不是一种类型。 尝试更正名称以匹配现有类型,显示冻结包错误 - Bloc error apiState dataloading isn't a type. Try correcting the name to match an existing type ,showing error with freezed package 错误:错误:没有为类型“_StoryPageState”定义方法“nextStory” - Error: error: The method 'nextStory' isn't defined for the type '_StoryPageState'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM