当前位置:网站首页>使用 BlocConsumer 同时构建响应式组件和监听状态
使用 BlocConsumer 同时构建响应式组件和监听状态
2022-07-04 21:33:00 【InfoQ】
前言
BlocListener
BlocBuilder
BlocBuilder
BlocListener
BlocBuilder
BlocListener
BlocConsumer
BlocConsumer实现机制
BlocConsumer
BlocBuilder
BlocListener
const BlocConsumer({
Key? key,
required this.builder,
required this.listener,
this.bloc,
this.buildWhen,
this.listenWhen,
}) : super(key: key);
builder
:响应式组件构造方法,和BlocBuilder
的相同。
listener
:状态变化处理监听回调函数,和BlocListener
的定义一致。
bloc
:可选的Bloc
状态对象,如果没有指定,会自动从当前的BuildContext
中查找对应类型的状态对象。
buildWhen
:可选参数,接收前后的状态对象,可以根据前后状态对象返回bool
值,若为true
才会刷新组件。
listenWhen
:可选参数,接收前后的状态对象,可以根据前后状态对象返回bool
值,若为true
才会调用listener
回调方法。
BlocConsumer
builder
@override
Widget build(BuildContext context) {
if (widget.bloc == null) context.select<B, int>(identityHashCode);
return BlocBuilder<B, S>(
bloc: _bloc,
builder: widget.builder,
buildWhen: (previous, current) {
if (widget.listenWhen?.call(previous, current) ?? true) {
widget.listener(context, current);
}
return widget.buildWhen?.call(previous, current) ?? true;
},
);
}
BlocBuilder
BlocBuilder
builderWhen
listenWhen
listener
BlocBuilder
BlocListener
BlocConsumer 应用

总结
BlocConsumer
BlocBuilder
BlocListener
BlocConsumer
BlocBuilder
BlocListener

边栏推荐
- Arcgis 10.2.2 | arcgis license server无法启动的解决办法
- 解析互联网时代的创客教育技术
- PostgreSQL基本结构——表
- vim 从嫌弃到依赖(23)——最后的闲扯
- How is the entered query SQL statement executed?
- The drawing method of side-by-side diagram, multi row and multi column
- Redis has three methods for checking big keys, which are necessary for optimization
- ArcGIS 10.2.2 | solution to the failure of ArcGIS license server to start
- [ 每周译Go ] 《How to Code in Go》系列文章上线了!!
- 创客思维在高等教育中的启迪作用
猜你喜欢
TCP protocol three times handshake process
How to remove the black dot in front of the title in word document
[weekly translation go] how to code in go series articles are online!!
【公开课预告】:视频质量评价基础与实践
Shutter textfield example
Compréhension approfondie du symbole [langue C]
案例分享|金融业数据运营运维一体化建设
Keep on fighting! The city chain technology digital summit was grandly held in Chongqing
el-tree结合el-table,树形添加修改操作
[C language] deep understanding of symbols
随机推荐
TCP shakes hands three times and waves four times. Do you really understand?
面试官:说说XSS攻击是什么?
Go language loop statement (3 in Lesson 10)
VS2019 C# release下断点调试
Kubeadm初始化报错:[ERROR CRI]: container runtime is not running
Jerry's ad series MIDI function description [chapter]
Numpy vstack and column_ stack
Cloudcompare & open3d DBSCAN clustering (non plug-in)
New intersectionobserver usage notes
LambdaQueryWrapper用法
AcWing 2022 每日一题
Interpreting the development of various intelligent organizations in maker Education
Relational database
Learning breakout 3 - about energy
El tree combined with El table, tree adding and modifying operations
HDU - 2859 Phalanx(DP)
Liu Jincheng won the 2022 China e-commerce industry innovation Figure Award
Delphi soap WebService server-side multiple soapdatamodules implement the same interface method, interface inheritance
TCP三次握手,四次挥手,你真的了解吗?
置信区间的画法