Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter: state management #227

Open
3 tasks done
hhstore opened this issue Oct 10, 2020 · 7 comments
Open
3 tasks done

Flutter: state management #227

hhstore opened this issue Oct 10, 2020 · 7 comments

Comments

@hhstore
Copy link
Owner

hhstore commented Oct 10, 2020

related:

@hhstore
Copy link
Owner Author

hhstore commented Oct 10, 2020

flutter 状态管理:

目前个人第一推荐: GetX

强烈不推荐 provider ! 请使用 GetX !
强烈不推荐 provider ! 请使用 GetX !
强烈不推荐 provider ! 请使用 GetX !

状态管理方案列表:

  • GetX: 简单. 非常棒! 是个严重被低估的项目.
  • Provider: ⭐⭐⭐⭐⭐ 官方首推. (实际使用体验一般, 更推荐 GetX)
  • 其他不推荐方案: (虽然都可以用, 但是没必要)
    • setState: 内置方案.
    • InheritedWidget & InheritedModel: 低层次.
    • Redux: ⭐⭐⭐ 成熟+复杂.
    • Fish Redux: ⭐⭐⭐⭐ 阿里加强版.
    • BLoC(business logic component)
    • RxDart: ⭐⭐⭐ 复杂. 基于 stream/observable.
    • MobX: ⭐⭐⭐⭐ 流行+推荐.

Provider: (过气方案/虽然官方推荐)

  • https://github.com/rrousselGit/provider
  • 官方推荐. 第一选择. (实际项目使用感受: 很一般, 好过狗屎 Redux, 但是不如 GetX)
  • 简单优雅, 易于使用+理解.
  • redux: 写法繁琐+难以理解.
  • bloc: 曾经推荐, 已过气.

一些讨论:

  • 经过实践对比, 还是 provider 更好用. 更推荐 GetX.
  • 其他方案, 不推荐新项目使用.
  • 老的项目, 看明白 redux, bloc 的用法, 逐步过渡.
  • 原理上, 都比较类似, 理解了 provider, 对于理解其他方案, 有帮助.

diff:

ref:

原理:

state-management-explainer-5495afe6c3d6162f145107fe45794583bc4f2b55be377c76a92ab210be74c033

  • Flutter is declarative.

image

  • Ephemeral state vs App state

image

示例代码:

@hhstore
Copy link
Owner Author

hhstore commented Oct 10, 2020

1

@hhstore
Copy link
Owner Author

hhstore commented Oct 10, 2020

xxxxxx:

xxxxxxxxxxxxxx xxxxxxxxxxxxxx xxxx
xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxx
xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxx
xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxx
xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxx
xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxx
xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxx
xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxx

@hhstore hhstore added Flutter Principle 原则: 第一性 labels Oct 10, 2020
@cvilia
Copy link

cvilia commented Nov 16, 2020

Getx也介绍一下呗,这个适不适合用啊,真怕跟fish-redux一样到最后半年不更新

@hhstore
Copy link
Owner Author

hhstore commented Nov 18, 2020

Getx也介绍一下呗,这个适不适合用啊,真怕跟fish-redux一样到最后半年不更新

  • GetX 很棒, 我最近会写个 GetX 的专题.
  • 实际使用体验比 Provider 好太多, 强推. 目前项目已经全面由Provider 切换到 GetX.
  • Provider 实际使用依旧很繁琐, 虽然比 Redux 好, 但是不够丝滑.
  • GetX 不只是提供状态管理, 包括路由跳转, 都做的非常好.

@cvilia

update: 关于 GetX 的介绍.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants