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... 阅读全文
Persistent storage architecture: SQL
Save complex application data to a user's device with SQL.
Most Flutter applications, no matter how small or big they are, might require storing data on the user’s device at some point. For example, API keys, user preferences or data that should be available offline.
In this recipe, you will learn how to integrate persistent storage for complex data using SQL in a Flutter application following the Flutter Architecture design pattern.
To read this recipe, you should be familiar with SQL and SQLite. If you need help,... 阅读全文
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. As well, they can be used to display... 阅读全文
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 的最新稳定版本,本页面最后更新时间: 2024-12-11。 查看文档源码 或者 为本页面内容提出建议。