当前位置:网站首页>使用 BlocConsumer 同时构建响应式组件和监听状态
使用 BlocConsumer 同时构建响应式组件和监听状态
2022-07-04 21:33:00 【InfoQ】
前言
BlocListenerBlocBuilderBlocBuilderBlocListenerBlocBuilderBlocListenerBlocConsumerBlocConsumer实现机制
BlocConsumerBlocBuilderBlocListenerconst 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回调方法。
BlocConsumerbuilder@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;
},
);
}
BlocBuilderBlocBuilderbuilderWhenlistenWhenlistenerBlocBuilderBlocListenerBlocConsumer 应用

总结
BlocConsumerBlocBuilderBlocListenerBlocConsumerBlocBuilderBlocListener
边栏推荐
- gtest从一无所知到熟练使用(3)什么是test suite和test case
- Golang interview finishing three resumes how to write
- GTEST from ignorance to proficiency (3) what are test suite and test case
- 哈希表(Hash Tabel)
- Bizchart+slider to realize grouping histogram
- Kubeadm初始化报错:[ERROR CRI]: container runtime is not running
- Go语言循环语句(第10课中3)
- gtest从一无所知到熟练使用(4)如何用gtest写单元测试
- Why do you have to be familiar with industry and enterprise business when doing Bi development?
- At the right time, the Guangzhou station of the city chain science and Technology Strategy Summit was successfully held
猜你喜欢

CloudCompare&Open3D DBSCAN聚类(非插件式)

Bookmark

From repvgg to mobileone, including mobileone code

Interpreting the development of various intelligent organizations in maker Education

Maidong Internet won the bid of Beijing life insurance

创客思维在高等教育中的启迪作用

历史最全混合专家(MOE)模型相关精选论文、系统、应用整理分享

Three or two things about the actual combat of OMS system

Master the use of auto analyze in data warehouse

LambdaQueryWrapper用法
随机推荐
Shutter WebView example
bizchart+slider实现分组柱状图
[wechat applet] collaborative work and release
Delphi soap WebService server-side multiple soapdatamodules implement the same interface method, interface inheritance
Jerry's ad series MIDI function description [chapter]
【C語言】符號的深度理解
MYSQL 用!=查询不出等于null的数据,解决办法
Basic structure of PostgreSQL - table
Operation of adding material schedule in SolidWorks drawing
面试官:说说XSS攻击是什么?
Monitor the shuttle return button
Cadeus has never stopped innovating. Decentralized edge rendering technology makes the metauniverse no longer far away
MP3是如何诞生的?
WebGIS framework -- kalrry
【米哈游2023届秋招】开启【校招唯一专属内推码EYTUC】
At the right time, the Guangzhou station of the city chain science and Technology Strategy Summit was successfully held
The drawing method of side-by-side diagram, multi row and multi column
如何使用ConcurrentLinkedQueue做一个缓存队列
For MySQL= No data equal to null can be found. Solution
Arcgis 10.2.2 | arcgis license server无法启动的解决办法