Skip to content

Commit 9209091

Browse files
authored
docs(dark-mode): 更新深色模式文档链接和代码示例 (Tencent#802)
* docs(dark-mode): 更新深色模式文档链接和代码示例 - 更新深色模式切换代码示例链接至实际文件路径 - 调整JSON配置代码块格式,统一缩进为两个空格 - 优化MaterialApp主题配置代码注释排版 - 修复themeMode属性重复声明的语法错误 * docs(dark-mode): 更新深色模式文档内容 - 修改了 MaterialApp 中 theme、darkTheme、themeMode 属性的注释说明 - 补充了主题切换需业务方自行实现的说明 - 提供了具体的代码示例文件路径引用 - 添加了关于 SharedPreferences 使用方式的注意事项 - 优化了文档中的代码块排版和注释格式 * docs(getting-started): 更新主题生成器深色模式版本说明 - 将深色模式支持的版本号链接化,方便用户直接查看更新日志 - 优化文档表述,使信息更加清晰易读
1 parent cee9ecb commit 9209091

File tree

2 files changed

+83
-80
lines changed

2 files changed

+83
-80
lines changed

tdesign-site/site/docs/dark-mode.md

Lines changed: 82 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ spline: explain
1313

1414
## 使用之前
1515

16-
使用之前,请先阅读 flutter 官方文档:[使用 Themes 统一颜色和字体风格](https://docs.flutter.cn/cookbook/design/themes)
16+
使用之前,请先阅读 flutter 官方文档:[使用 Themes 统一颜色和字体风格](https://docs.flutter.cn/cookbook/design/themes/)
1717

1818
TDFlutter 的深色模式是基于上述 flutter 官方文档对 [ThemeData](https://api.flutter-io.cn/flutter/material/ThemeData-class.html) 进行自定义配置和重载主题实现的。
1919

20-
具体代码请参考 [深色模式切换](https://github.com/Tencent/tdesign-flutter/pull/768/commits/c5bf979a4b54c119e196ced2f6006deb69339fde)
20+
具体代码请参考 [深色模式切换](https://github.com/Tencent/tdesign-flutter/blob/develop/tdesign-component/example/lib/component_test/dark_test.dart)
2121

2222
## 主题配置
2323

@@ -30,60 +30,60 @@ TDFlutter 的深色模式是基于上述 flutter 官方文档对 [ThemeData](htt
3030
```json
3131
{
3232
"defaultDark": {
33-
"ref": {
34-
"brandNormalColor": "brandColor8",
35-
"warningNormalColor": "warningColor5",
36-
"errorNormalColor": "errorColor6",
37-
"successNormalColor": "successColor5",
38-
"brandFocusColor": "brandColor1",
39-
"brandActiveColor": "brandColor9",
40-
"brandDisabledColor": "brandColor3",
41-
"brandLightColor": "brandColor1",
42-
"brandColorLightActive": "brandColor2",
43-
"warningFocusColor": "warningColor2",
44-
"warningActiveColor": "warningColor4",
45-
"warningDisabledColor": "warningColor3",
46-
"warningLightColor": "warningColor1",
47-
"warningColorLightActive": "warningColor2",
48-
"errorFocusColor": "errorColor2",
49-
"errorActiveColor": "errorColor5",
50-
"errorDisabledColor": "errorColor3",
51-
"errorLightColor": "errorColor1",
52-
"errorColorLightActive": "errorColor2",
53-
"successFocusColor": "successColor2",
54-
"successActiveColor": "successColor4",
55-
"successDisabledColor": "successColor3",
56-
"successLightColor": "successColor1",
57-
"successColorLightActive": "successColor2",
58-
"bgColorPage": "grayColor14",
59-
"bgColorContainer": "grayColor13",
60-
"bgColorSecondaryContainer": "grayColor12",
61-
"bgColorComponent": "grayColor11",
62-
"bgColorContainerActive": "grayColor12",
63-
"bgColorSecondaryContainerActive": "grayColor11",
64-
"bgColorComponentActive": "grayColor10",
65-
"bgColorComponentDisabled": "grayColor12",
66-
"textColorPrimary": "fontWhColor1",
67-
"textColorSecondary": "fontWhColor2",
68-
"textColorPlaceholder": "fontWhColor3",
69-
"textDisabledColor": "fontWhColor4",
70-
"textColorAnti": "fontWhColor1",
71-
"textColorBrand": "brandColor8",
72-
"textColorLink": "brandColor8",
73-
"componentStrokeColor": "grayColor11",
74-
"componentBorderColor": "grayColor9"
75-
},
76-
"color": {
77-
"brandColor1": "#1b2f51",
78-
"brandColor2": "#173463",
79-
"brandColor3": "#143975",
80-
"brandColor4": "#103d88",
81-
"brandColor5": "#0d429a",
82-
"brandColor6": "#054bbe",
83-
"brandColor7": "#2667d4",
84-
"brandColor8": "#4582e6",
85-
"brandColor9": "#699ef5",
86-
"brandColor10": "#96bbf8"
33+
"ref": {
34+
"brandNormalColor": "brandColor8",
35+
"warningNormalColor": "warningColor5",
36+
"errorNormalColor": "errorColor6",
37+
"successNormalColor": "successColor5",
38+
"brandFocusColor": "brandColor1",
39+
"brandActiveColor": "brandColor9",
40+
"brandDisabledColor": "brandColor3",
41+
"brandLightColor": "brandColor1",
42+
"brandColorLightActive": "brandColor2",
43+
"warningFocusColor": "warningColor2",
44+
"warningActiveColor": "warningColor4",
45+
"warningDisabledColor": "warningColor3",
46+
"warningLightColor": "warningColor1",
47+
"warningColorLightActive": "warningColor2",
48+
"errorFocusColor": "errorColor2",
49+
"errorActiveColor": "errorColor5",
50+
"errorDisabledColor": "errorColor3",
51+
"errorLightColor": "errorColor1",
52+
"errorColorLightActive": "errorColor2",
53+
"successFocusColor": "successColor2",
54+
"successActiveColor": "successColor4",
55+
"successDisabledColor": "successColor3",
56+
"successLightColor": "successColor1",
57+
"successColorLightActive": "successColor2",
58+
"bgColorPage": "grayColor14",
59+
"bgColorContainer": "grayColor13",
60+
"bgColorSecondaryContainer": "grayColor12",
61+
"bgColorComponent": "grayColor11",
62+
"bgColorContainerActive": "grayColor12",
63+
"bgColorSecondaryContainerActive": "grayColor11",
64+
"bgColorComponentActive": "grayColor10",
65+
"bgColorComponentDisabled": "grayColor12",
66+
"textColorPrimary": "fontWhColor1",
67+
"textColorSecondary": "fontWhColor2",
68+
"textColorPlaceholder": "fontWhColor3",
69+
"textDisabledColor": "fontWhColor4",
70+
"textColorAnti": "fontWhColor1",
71+
"textColorBrand": "brandColor8",
72+
"textColorLink": "brandColor8",
73+
"componentStrokeColor": "grayColor11",
74+
"componentBorderColor": "grayColor9"
75+
},
76+
"color": {
77+
"brandColor1": "#1b2f51",
78+
"brandColor2": "#173463",
79+
"brandColor3": "#143975",
80+
"brandColor4": "#103d88",
81+
"brandColor5": "#0d429a",
82+
"brandColor6": "#054bbe",
83+
"brandColor7": "#2667d4",
84+
"brandColor8": "#4582e6",
85+
"brandColor9": "#699ef5",
86+
"brandColor10": "#96bbf8"
8787
}
8888
}
8989
}
@@ -119,29 +119,30 @@ class App extends StatelessWidget {
119119
120120
@override
121121
Widget build(BuildContext context) {
122-
// MaterialApp中设置theme,darkTheme,themeMode三个属性如下,如果有自定义主题属性,可以通过copyWith()方法修改。
123-
// 注:主题切换需要业务自己实现,比如使用Provider,具体可参考tdesign-flutter/tdesign-component/example/lib/component_test/dark_test.dart
124-
return MaterialApp(
125-
title: '深色模式切换测试',
126-
127-
/// 默认浅色模式
128-
theme: themeData.systemThemeDataLight!.copyWith(
129-
/// 根据自己的需求用 TD 颜色覆盖 Material/Cupertino 的颜色
130-
cupertinoOverrideTheme: const CupertinoThemeData().copyWith(
131-
barBackgroundColor: themeData.bgColorContainer.withOpacity(0.5),
132-
),
133-
/// ... 更多重载主题
134-
),
135-
136-
/// 深色模式
137-
darkTheme: themeData.systemThemeDataDark?.copyWith(
138-
cupertinoOverrideTheme: const CupertinoThemeData().copyWith(
139-
barBackgroundColor: themeData.dark?.grayColor13.withOpacity(0.5),
140-
),
122+
/// MaterialApp 中设置 theme、darkTheme、themeMode 三个属性
123+
/// 如下所示,如果有自定义主题属性,可以通过 copyWith() 方法修改。
124+
/// 注:主题切换需要业务自己实现,比如使用 Provider
125+
/// 具体可参考 tdesign-flutter/tdesign-component/example/lib/component_test/dark_test.dart
126+
return MaterialApp(
127+
title: '深色模式切换测试',
128+
129+
/// 默认浅色模式
130+
theme: themeData.systemThemeDataLight!.copyWith(
131+
/// 根据自己的需求用 TD 颜色覆盖 Material/Cupertino 的颜色
132+
cupertinoOverrideTheme: const CupertinoThemeData().copyWith(
133+
barBackgroundColor: themeData.bgColorContainer.withOpacity(0.5),
134+
),
135+
/// ... 更多重载主题
136+
),
141137
142-
/// ... 更多重载主题
143-
),
144-
themeMode: themeModeProvider.themeMode,
138+
/// 深色模式
139+
darkTheme: themeData.systemThemeDataDark?.copyWith(
140+
cupertinoOverrideTheme: const CupertinoThemeData().copyWith(
141+
barBackgroundColor: themeData.dark?.grayColor13.withOpacity(0.5),
142+
),
143+
/// ... 更多重载主题
144+
),
145+
themeMode: themeModeProvider.themeMode,
145146
);
146147
}
147148
}
@@ -161,7 +162,7 @@ return MaterialApp(
161162
// 深色模式(已忽略细节)
162163
darkTheme: _themeData.systemThemeDataDark,
163164
// MaterialApp 主题模式默认跟随系统
164-
themeMode: themeMode: ThemeMode.system,
165+
themeMode: ThemeMode.system,
165166
);
166167
```
167168

@@ -180,6 +181,8 @@ return MaterialApp(
180181
181182
1. 新建 `ThemeModeProvider` 类,并继承 `ChangeNotifier`,添加主题模式属性和切换主题模式的方法。并使用 `SharedPreferencesAsync` 持久化主题模式。
182183

184+
注:旧版本的 `shared_preferences` 包请使用 `SharedPreferences.getInstance();`,具体请参考 [shared_preferences](https://pub.dev/packages/shared_preferences) 文档。
185+
183186
```dart
184187
import 'package:flutter/material.dart';
185188
import 'package:shared_preferences/shared_preferences.dart';

tdesign-site/site/docs/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ TDTheme.defaultData().fontBodyLarge
7777
7878
### 主题生成器
7979
如果你不想自定义太多颜色,但是想要拥有好看的自定义主题,“主题生成器”是个不错的选择。
80-
* 注: 0.2.6版本开始,主题生成器已支持“深色模式”,具体可参考[深色模式](https://tdesign.tencent.com/flutter/dark-mode) *
80+
* 注:[0.2.6](https://tdesign.tencent.com/flutter/changelog#%F0%9F%8C%88-0-2-6-2025-11-14) 版本开始,主题生成器已支持“深色模式”,具体可参考[深色模式](https://tdesign.tencent.com/flutter/dark-mode)
8181
8282
1. 进入[TDesign官网](https://tdesign.tencent.com/vue/custom-theme),点击下方的主题生成器,然后再右边生成器里选择想要的颜色,点击下载。
8383

0 commit comments

Comments
 (0)