11---
22# title: "Persistent storage architecture: Key-value data"
3- title : 持久存储架构:键值对数据
3+ title : 持久存储架构:键值对数据
44# description: Save application data to a user's on-device key-value store.
55description : 以键值对形式将应用产生的数据保存到用户的设备中。
66contentTags :
@@ -94,13 +94,16 @@ This functionality follows the recommended Flutter architecture design pattern,
9494with a presentation and a data layer.
9595
9696此功能遵循推荐的 Flutter 架构设计,
97- 包含展示层和数据层( Data Layer) 。
97+ 包含展示层和数据层 ( Data Layer) 。
9898
9999- The presentation layer contains the ` ThemeSwitch ` widget
100100and the ` ThemeSwitchViewModel ` .
101+
101102 展示层包含 ` ThemeSwitch ` 组件和 ` ThemeSwitchViewModel ` 。
103+
102104- The data layer contains the ` ThemeRepository `
103105and the ` SharedPreferencesService ` .
106+
104107 数据层包含 ` ThemeRepository ` 和 ` SharedPreferencesService ` 。
105108
106109### Theme selection presentation layer
@@ -113,9 +116,9 @@ by the public field `isDarkMode` in the `ThemeSwitchViewModel`.
113116When the user taps the switch,
114117the code executes the command ` toggle ` in the view model.
115118
116- ` ThemeSwitch ` 是一个 ` StatelessWidget ` ,它包含一个 ` Switch ` 组件。
119+ ` ThemeSwitch ` 是一个 ` StatelessWidget ` ,它包含一个 ` Switch ` 组件。
117120开关的状态由 ` ThemeSwitchViewModel ` 中的公共字段 ` isDarkMode ` 表示。
118- 当用户点击开关时,代码执行视图模型中的命令 ` toggle ` 。
121+ 当用户点击开关时,代码执行视图模型中的命令 ` toggle ` 。
119122
120123<? code-excerpt "lib/ui/theme_config/widgets/theme_switch.dart (ThemeSwitch)"?>
121124``` dart
@@ -241,7 +244,7 @@ the `ThemeRepository` and the `SharedPreferencesService`.
241244
242245根据架构指南,
243246数据层被分为两部分:
244- ` ThemeRepository ` 和 ` SharedPreferencesService ` 。
247+ ` ThemeRepository ` 和 ` SharedPreferencesService ` 。
245248
246249The ` ThemeRepository ` is the single source of truth
247250for all the theming configuration settings,
@@ -264,7 +267,7 @@ The `ThemeRepository` depends on `SharedPreferencesService`.
264267The repository obtains the stored value from the service,
265268and stores it when it changes.
266269
267- ` ThemeRepository ` 依赖于 ` SharedPreferencesService ` 。
270+ ` ThemeRepository ` 依赖于 ` SharedPreferencesService ` 。
268271该主题仓库从服务中获取存储的值,
269272并存储其改变后的值。
270273
@@ -324,7 +327,7 @@ hiding this third-party dependency from the rest of the application
324327A third-party dependency is a way to refer to packages and plugins
325328developed by other programmers outside of your organization.
326329
327- 第三方依赖是指引用组织外程序员开发的 packages 和插件的一种方式。
330+ 第三方依赖是指引用组织外程序员开发的 package 和插件的一种方式。
328331:::
329332
330333<? code-excerpt "lib/data/services/shared_preferences_service.dart (SharedPreferencesService)"?>
@@ -355,7 +358,7 @@ and passed to the `MainApp` as constructor argument dependency.
355358
356359在本示例中,
357360` ThemeRepository ` 和 ` SharedPreferencesService ` 是在 ` main() ` 方法中创建的,
358- 并作为构造函数参数依赖项传递给 ` MainApp ` 。
361+ 并作为构造函数参数依赖项传递给 ` MainApp ` 。
359362
360363<? code-excerpt "lib/main.dart (MainTheme)"?>
361364``` dart
@@ -390,7 +393,7 @@ which listens to changes in the `ThemeRepository`
390393and exposes the dark mode setting to the ` MaterialApp ` widget.
391394
392395该示例程序还包括 ` MainAppViewModel ` 类,
393- 该类监听 ` ThemeRepository ` 的变化并向 ` MaterialApp ` 小部件暴露深色模式设置 。
396+ 该类监听 ` ThemeRepository ` 的变化并向 ` MaterialApp ` widget 暴露深色模式设置 。
394397
395398<? code-excerpt "lib/main_app_viewmodel.dart (MainAppViewModel)"?>
396399``` dart
0 commit comments