class _HomePageState extends State<HomePage> {
late ArticleBloc articleBloc;
@override
void initState() {
super.initState();
articleBloc = BlocProvider.of<ArticleBloc>(context);
articleBloc.add(FetchArticlesEvent());
}
@override
Widget build(BuildContext context) {
return Container();
}
}
Run Code Online (Sandbox Code Playgroud)
它以前可以工作,但现在代码不起作用。
我尝试了很多搜索但失败了。
这是错误:
错误状态:在没有注册事件处理程序的情况下调用 add(FetchArticlesEvent)。
tol*_*ler 11
您必须按如下方式注册 FetchArticlesEvent 类。如果您尝试使用尚未注册的事件,您将收到此错误。
class ArticleBloc extends Bloc<ArticleEvent, ArticleState> {
ArticleBloc() : super(ArticleInitial()) {
on<FetchArticlesEvent>((event, emit) {
//TODO
});
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24265 次 |
| 最近记录: |