Architecture design patterns
If you've already read through the architecture guide page, or if you're comfortable with Flutter and the MVVM pattern, the following articles are for you.
These articles aren't about high-level app architecture, rather they're about solving specific design problems that improve your application's code base regardless of how you've architected your app. That said, the articles do assume the MVVM pattern laid out on the previous pages in the code examples.
Optimistic state
Improve the perception of responsiveness of an application by implementing optimistic state.
Developers can help mitigate this negative perception by presenting a successful UI state before the background task is fully completed. An example of this would be tapping a “Subscribe” button, and seeing it change to “Subscribed” instantly, even if the background call to the... 阅读全文
Persistent storage architecture: Key-value data
Save application data to a user's on-device key-value store.
Most Flutter applications, no matter how small or big they are, require storing data on the user’s device at some point, such as API keys, user preferences or data that should be available offline.
Key-value stores are often used for saving simple data, such as app configuration, and in this... 阅读全文
持久化存储架构:SQL
采用 SQL 将复杂的应用数据存储至用户设备。
大多数 Flutter 应用程序,无论规模大小,往往需要在用户设备上存储数据。例如:API 密钥、用户偏好内容,以及需要支持离线访问的数据。
在本教程中,你将学习如何遵循 Flutter 架构设计模式,并在 Flutter 应用中实现基于 SQL 的复杂数据持久化存储。
To learn how to store simpler key-value data, take a look at the Cookbook recipe: Persistent storage architecture: Key-value data.
... 阅读全文Offline-first support
Implement offline-first support for one feature in an application.
Some offline-first applications combine local and remote data seamlessly, while other applications inform the user when the application is using cached data. In the same way, some applications synchronize data in the background while others require the user to explicitly synchronize it. It all depends on the application requirements and the functionality it offers, and it’s... 阅读全文
The command pattern
Simplify view model logic by implementing a Command class.
Model-View-ViewModel (MVVM) is a design pattern that separates a feature of an application into three parts: the model, the view model, and the view. Views and view models make up the UI layer of an application. Repositories and services represent the data layer of an application, or the model layer of MVVM.
View models can use commands to handle interaction and run actions. You can also use them to display different... 阅读全文
Error handling with Result objects
Improve error handling across classes with Result objects.
Dart provides a built-in error handling mechanism with the ability to throw and catch exceptions.
As mentioned in the Error handling documentation, Dart's exceptions are unhandled exceptions. This means that methods that throw exceptions don’t need to declare them, and calling methods aren't required to catch them either.
In this guide, you will learn about this limitation... 阅读全文
除非另有说明,本文档之所提及适用于 Flutter 的最新稳定版本,本页面最后更新时间: 2025-09-05。 查看文档源码 或者 为本页面内容提出建议.