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.
When building user experiences, the perception of performance is sometimes just as important as the actual performance of the code. In general, users don’t like waiting for an action to finish to see the result, and anything that takes more than a few milliseconds could be considered “slow” or “unresponsive” from the user’s perspective.
持久存储架构:键值对数据
以键值对形式将应用产生的数据保存到用户的设备中。
大多数 Flutter 应用程序,无论规模大小,往往需要在用户设备上存储数据。例如:API 密钥、用户偏好内容,以及需要支持离线访问的数据。
在本教程中,你将学习如何遵循 Flutter 架构设计模式,并在 Flutter 应用中实现基于键值对的数据持久化存储。如果你尚且不熟悉如何将数据存储到磁盘上,可以阅读 ...
持久化存储架构:SQL
采用 SQL 将复杂的应用数据存储至用户设备。
大多数 Flutter 应用程序,无论规模大小,往往需要在用户设备上存储数据。例如:API 密钥、用户偏好内容,以及需要支持离线访问的数据。
在本教程中,你将学习如何遵循 Flutter 架构设计模式,并在 Flutter 应用中实现基于 SQL 的复杂数据持久化存储。
如果你需要了解如何存储更简单的键值 ...
Offline-first support
Implement offline-first support for one feature in an application.
An offline-first application is an app capable of offering most or all of its functionality while being disconnected from the internet. Offline-first applications usually rely on stored data to offer users temporary access to data that would otherwise only be available online.
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.
A command is a class that wraps a method and helps to handle the different states of that method, such as running, complete, and error.
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.
This can lead to situations where exceptions are not handled properly. In large projects, developers might forget to catch exceptions, and the different application layers and components could throw exceptions that aren’t documented. This can lead to errors and crashes.
除非另有说明,本文档之所提及适用于 Flutter 3.38.1 版本。本页面最后更新时间:2025-10-28。查看文档源码 或者 为本页面内容提出建议。