简体   繁体   English

如果您在 BlocBuilder 中指定 bloc,flutter_bloc 会处理 cubit 吗?

[英]Does flutter_bloc dispose of the cubit if you specify the bloc in the BlocBuilder?

I've seen BlocProvider automatically disposes of the bloc in the flutter_bloc package.我已经看到BlocProvider自动处理flutter_bloc package 中的 bloc。 Is this also the case when specifying the bloc/cubit scoped to a single widget?将 bloc/cubit 范围指定为单个小部件时也是这种情况吗?

BlocBuilder<BlocA, BlocAState>(
  cubit: blocA, // provide the local cubit instance
  builder: (context, state) {
    // return widget here based on BlocA's state
  }
)

(I seem to be creating multiply instances of my cubit) (我似乎正在创建我的肘部的多个实例)

BlocBuilder has nothing to do with dispose of a bloc instance. BlocBuilder与处理 bloc 实例无关。 It is BlocProvider , that takes care of it automatically.它是BlocProvider ,它会自动处理它。 The only case, when you have to dispose of a bloc instance manually, is when you provide it to next widget tree with BlocProvider.value .唯一的情况是,当您必须手动处理 bloc 实例时,是当您使用BlocProvider.value将其提供给下一个小部件树时。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM