issues
search
hhstore
/
blog
My Tech Blog: about Mojo / Rust / Golang / Python / Kotlin / Flutter / VueJS / Blockchain etc.
https://github.com/hhstore/blog/issues
291
stars
24
forks
source link
Flutter: BLoC
#218
Open
hhstore
opened
4 years ago
hhstore
commented
4 years ago
related:
[x] #235 : GetX - 更好的状态管理方案.
[x] #215
[x] #202
hhstore
commented
4 years ago
flutter bloc:
[x] 不推荐任何人使用,
过气
方案! 请使用
GetX
, 更好选择, 没有之一.
[x] 不推荐任何人使用,
过气
方案! 请使用
GetX
, 更好选择, 没有之一.
[x] 不推荐任何人使用,
过气
方案! 请使用
GetX
, 更好选择, 没有之一.
简介:
[x] 一种 flutter 的 数据状态管理方案, 已过时.
[x] Bloc 是英文
Business Logic Component
的缩写
[x] 是一种面向组件和业务逻辑的分离的优雅策略
[x]
https://github.com/felangel/bloc
[x]
https://github.com/felangel/bloc/tree/master/packages/flutter_bloc
背景:
Flutter的很多灵感来自于React.
scoped model与redux两种状态管理方案
Google 官方提出的推荐方案:
BLoC
是什么:
[x] 一种设计模式
[x] 利用reactive programming方式构建应用的方法,这是一个由流构成的完全异步的世界。
细节:
[x] 用StreamBuilder包裹有状态的部件,streambuilder将会监听一个流
[x] 这个流来自于BLoC
[x] 有状态小部件中的数据来自于监听的流。
[x] 用户交互手势被检测到,产生了事件。例如按了一下按钮。
[x] 调用bloc的功能来处理这个事件
[x] 在bloc中处理完毕后将会吧最新的数据add进流的sink中
[x] StreamBuilder监听到新的数据,产生一个新的snapshot,并重新调用build方法
[x] Widget被重新构建
优点:
[x]业务逻辑和 Widget 的分离
[x]可单独测试业务逻辑
[x]可更好的重用业务逻辑代码
数据流:
[x] 数据从 Bloc 而来,从 Stream 而出,最后落地到更新 Widget 上
hhstore
commented
4 years ago
ref:
https://www.didierboelens.com/2018/08/reactive-programming-streams-bloc/
官方介绍
https://zhuanlan.zhihu.com/p/55842307
https://juejin.im/post/6844903689082109960
https://juejin.im/post/6844903812059103245
https://juejin.im/post/6844903812063297544
https://juejin.im/post/6844903812059103239
hhstore
commented
4 years ago
基于项目理解 bloc:
https://github.com/better-dart/FlutterUnit
参考此项目对 bloc 的用法.
related: