Skip to content

Commit 2a9460c

Browse files
authored
breaking(TSwitch): 独立加载状态并收敛示例 (#1050)
1 parent a9e12d0 commit 2a9460c

28 files changed

Lines changed: 591 additions & 128 deletions
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# 验收记录
2+
3+
## 验证环境
4+
5+
- 分支:rss1102/style/switch-miniprogram-alignment
6+
- 提交:本 Spec 与 breaking API 实现一并提交
7+
- Flutter/Dart:Flutter 3.32.0 / Dart 3.8.0;latest 待 CNB CI 验证
8+
9+
## 自动化验证
10+
11+
| 命令 | 结果 | 备注 |
12+
| --- | --- | --- |
13+
| `flutter test test/components/switch/t_switch_test.dart --coverage` | 通过 | 15 项;Switch 生产目录 341/358,95.25% |
14+
| `flutter test test/switch_page_test.dart --coverage` | 通过 | 4 项;Demo 49/49,100%;light/dark Golden 非更新模式通过 |
15+
| `flutter analyze`(tdesign-component) | 通过 | 0 issues |
16+
| `flutter analyze`(example) | 通过 | 0 issues |
17+
| `dart run tool/generate_example_code.dart --check --verbose` | 通过 | 所有片段已同步 |
18+
| `node tool/generate_api.mjs` | 通过 | Switch API 文档已同步 |
19+
| `git diff --check` | 通过 | 无空白错误 |
20+
21+
## 人工验收
22+
23+
- [ ] Android 实机确认 Switch 加载状态与分组展示
24+
25+
## 未覆盖项与后续工作
26+
27+
- Flutter latest 依赖 CNB CI 验证;本地未安装第二套 SDK。
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# 实施方案
2+
3+
## 技术方案
4+
5+
在 TSwitch 上新增必选默认值参数 `loading = false`,并从
6+
`TSwitchVariant` 删除 `loading`。构建时先根据 `loading` 决定交互能力和
7+
加载指示器,再由 `variant` 处理非加载内容形态,避免两个加载状态源。
8+
9+
## 影响范围
10+
11+
| 范围 | 文件或模块 | 影响 |
12+
| --- | --- | --- |
13+
| 组件 | switch/t_switch.dart、t_switch_types.dart | breaking API 收敛 |
14+
| 测试 | t_switch_test.dart、switch_page_test.dart | 更新加载态和回归覆盖 |
15+
| 示例 | t_switch_page.dart、Golden、生成片段 | 迁移到 loading 参数 |
16+
| 文档 | Switch API 产物、Spec | 记录新契约和迁移方式 |
17+
18+
## API 变化
19+
20+
- 新增 `TSwitch.loading`,默认 `false`
21+
- 删除 `TSwitchVariant.loading`
22+
- 迁移:`variant: TSwitchVariant.loading` 改为 `loading: true`
23+
24+
## 风险与取舍
25+
26+
- 删除枚举值是 breaking change,不保留兼容别名,以免形成双状态源。
27+
- loading 与 variant 同时传入时,loading 负责当前状态并覆盖滑块内容;
28+
loading 结束后恢复 variant 指定的内容形态。
29+
30+
## 验证策略
31+
32+
- 单元测试:加载渲染、禁用交互、variant 恢复和 API 形态。
33+
- 集成或 Widget 测试:Demo 状态矩阵、交互及 light/dark Golden。
34+
- 静态检查:组件包和 Example 包 flutter analyze。
35+
- 人工验收:Android 实机查看加载、禁用、尺寸分组。
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# TSwitch 加载状态 API 收敛
2+
3+
## 背景
4+
5+
`TSwitchVariant` 同时包含 `filled``text``icon` 三种内容形态和
6+
`loading` 状态,导致同一枚举混合展示形态与交互状态。加载状态需要成为
7+
独立且唯一的公开状态源。
8+
9+
## 目标
10+
11+
-`final bool loading` 作为 TSwitch 加载状态的唯一入口。
12+
- `TSwitchVariant` 只保留 `filled``text``icon` 三种内容形态。
13+
- 加载中显示加载指示器并禁用交互。
14+
- 同步示例、测试、Golden、API 文档和迁移说明。
15+
16+
## 非目标
17+
18+
- 不新增 `disabled`,禁用仍由 `onChanged == null` 表达。
19+
- 不引入非受控值或自定义值类型。
20+
- 不改变尺寸、颜色和主题优先级。
21+
22+
## 范围
23+
24+
### 涉及
25+
26+
- TSwitch 构造参数、加载渲染与交互语义。
27+
- TSwitchVariant 枚举。
28+
- Switch 组件测试、示例测试、示例代码和 Golden。
29+
- 生成的 Switch API 文档与代码片段。
30+
31+
### 不涉及
32+
33+
- TCupertinoSwitch 公开契约。
34+
- ExampleItem、ExamplePage 或公共 Example 抽象。
35+
36+
## 行为契约
37+
38+
- `loading` 默认为 `false`
39+
- `loading == true` 时,滑块内容显示加载指示器,`onChanged` 不会触发,
40+
语义节点为不可交互。
41+
- `loading == false` 时,`variant` 决定 `filled``text``icon` 内容形态。
42+
- `TSwitchVariant.loading` 被删除;迁移方式为
43+
`variant: TSwitchVariant.loading``loading: true`
44+
- `onChanged == null` 仍是普通禁用状态的唯一入口。
45+
46+
## 验收标准
47+
48+
- [ ] TSwitchVariant 仅保留 filled、text、icon。
49+
- [ ] TSwitch 仅通过 loading 表达加载状态,默认值为 false。
50+
- [ ] 加载态渲染、禁用交互和语义测试通过。
51+
- [ ] 示例、代码片段、API 文档与 Golden 同步。
52+
- [ ] Switch 生产目录覆盖率不低于 95%。
53+
- [ ] Flutter 3.32.0 与 latest 的 analyze/test 门禁通过。
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# 实施任务
2+
3+
- [x] DONE 明确需求和验收边界
4+
- [x] DONE 完成实现
5+
- [x] DONE 补充或更新测试
6+
- [x] DONE 更新示例和 API 文档
7+
- [x] DONE 执行验证并记录结果
8+
- [x] DONE 完成 Review

tdesign-component/example/assets/api/switch_api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
| --- | --- | --- | --- |
77
| closeText | String? | - | text 形态的关闭文案。 |
88
| key | Key? | - | 组件标识,用于区分或保留组件状态。 |
9+
| loading | bool | false | 是否处于加载状态;加载时显示指示器并禁用交互。 |
910
| onChanged | ValueChanged<bool>? | - | 开关状态变更回调;为 null 时禁用。 |
1011
| openText | String? | - | text 形态的开启文案。 |
1112
| size | TSwitchSize? | - | 开关尺寸;未传时读取 `TSwitchThemeData.defaultSize`|
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Widget _buildBasic(BuildContext context) => const TCell(
2-
title: Text('基础开关'),
3-
note: _StatefulSwitch(),
4-
);
2+
title: Text('基础开关'),
3+
note: _StatefulSwitch(initialValue: true),
4+
);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Widget _buildColor(BuildContext context) => Theme(
2+
data: Theme.of(
3+
context,
4+
).mergeExtension(const TSwitchThemeData(trackOnColor: Color(0xFF00A870))),
5+
child: const TCell(
6+
title: Text('自定义颜色开关'),
7+
note: _StatefulSwitch(initialValue: true),
8+
),
9+
);

tdesign-component/example/assets/code/switch._buildDisabled.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

tdesign-component/example/assets/code/switch._buildIcon.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Widget _buildLabel(BuildContext context) => const TCellGroup(
2+
cells: [
3+
TCell(
4+
title: Text('带文字开关'),
5+
note: _StatefulSwitch(
6+
initialValue: true,
7+
variant: TSwitchVariant.text,
8+
openText: '开',
9+
closeText: '关',
10+
),
11+
),
12+
TCell(
13+
title: Text('带图标开关'),
14+
note: _StatefulSwitch(initialValue: true, variant: TSwitchVariant.icon),
15+
),
16+
],
17+
);

0 commit comments

Comments
 (0)