状态管理是一个相当复杂的话题。如果你在浏览后发现一些问题并未得到解答,或者并不适用于你的具体需求场景,自信些,你的实现就是对的。

通过下面的资源了解更多的信息,其中有很多内容都是由社区(第三方)提供。

总体概览

#

在选择一个具体内容前,你可以先查看以下几项。

内置的方式

#

setState

#

用于 Widget 临时状态的基础方式。

ValueNotifierInheritedNotifier

#

一种完全使用 Flutter 提供的 API 来更新状态并通知 UI 更新的方式。

InheritedWidgetInheritedModel

#

Widget tree 中不同层级间的 widget 通信的基础方法。这是诸如 package:provider 等众多方法的底层实现。

以下讲师指导的视频 workshop 介绍了如何使用 InheritedWidget

其他有用的文档包括:

社区提供的 package

#

Depending on the complexity of your app and preferences of your team, you might find adopting a state management package useful. State management packages often help reduce boilerplate code, provide specialized debugging tools, and can help enable a clearer and consistent application architecture.

The Flutter community offers a wide variety of state management packages. The best choice for your app often depends on the app's complexity, your team's preferences, and the specific problems you need to solve.

To begin exploring the available options, check out the #state-management topic on the pub.dev site and refine the search to find packages that match your needs.