在一个类中,我有一个BlocProvider,然后我想显示一个对话框,其中我有一个BlocBuilder。但我认为,由于函数showDialog(),我有以下错误:
BlocProvider.of()使用不包含
块的上下文调用
发布于 2020-10-25 17:30:36
存储context
of BlocBuilder
作为字段:
BuildContext _bloxContext;
...
BlocBuilder<BlocClass, BaseState>(
builder: (mContext, state) {
if (_bloxContext == null) _bloxContext = mContext;
}
),
在你想要的任何地方使用它:
BlocProvider.of<BlocClass>(mContext).add(Fetch());
我希望这对你有用。
https://stackoverflow.com/questions/64526558
复制相似问题