跳转至正文

架构设计模式

关于构建 Flutter 应用时有用的设计模式的文章合集。

若你已阅读 架构指南 页面,或已熟悉 Flutter 与 MVVM 模式,以下文章适合你。

这些文章不讨论高层应用架构,而是聚焦解决特定设计问题,无论你的应用采用何种架构都能改善代码库。不过,文中代码示例假定采用前几页介绍的 MVVM 模式。

构建用户体验时,性能感知有时与代码实际性能同样重要。通常用户不愿等操作完成才看到结果,超过几毫秒的操作在用户看来可能显得「慢」或「无响应」。

阅读全文

大多数 Flutter 应用程序,无论规模大小,往往需要在用户设备上存储数据。例如:API 密钥、用户偏好内容,以及需要支持离线访问的数据。

在本教程中,你将学习如何遵循 Flutter 架构设计模式,并在 Flutter 应用中实现基于键值对的数据持久化存储。如果你尚且不熟悉如何将数据存储到磁盘上,可以阅读 ...

阅读全文

大多数 Flutter 应用程序,无论规模大小,往往需要在用户设备上存储数据。例如:API 密钥、用户偏好内容,以及需要支持离线访问的数据。

在本教程中,你将学习如何遵循 Flutter 架构设计模式,并在 Flutter 应用中实现基于 SQL 的复杂数据持久化存储。

如果你需要了解如何存储更简单的键值 ...

阅读全文

离线优先应用可在断网时提供大部分或全部功能。 Offline-first applications usually rely on stored data to offer users temporary access to data that would otherwise only be available online.

离线优先应用通常依赖已存储数据,让用户临时访问原本仅在线可用的数据。

阅读全文

Model-View-ViewModel (MVVM) 是一种设计模式,将应用的一个功能拆为 model、view model 与 view 三部分。 View 与 view model 构成应用的 UI 层;仓库与 service 代表数据层,即 MVVM 的 model 层。

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.

阅读全文

Dart 提供内置错误处理机制,支持抛出与捕获异常。

错误处理文档 所述,Dart 的异常是未处理异常(unhandled exceptions)。这意味着抛出异常的方法无需声明异常,调用方也不必捕获。

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.

阅读全文