Repository navigation
fix(theme): 补齐 TargetPlatform 通配分支,修复扩展平台编译报错 - #1220
Merged
RSS1102 merged 5 commits intoDec 2, 2026
Merged
Conversation
`t_internal_material.dart` 中两处 switch 只列出 TargetPlatform 的六个已发布 枚举值。Dart 3 的穷尽性检查在枚举被扩展的 SDK 上会直接编译失败,例如 Flutter-OHOS 新增 `TargetPlatform.ohos`: - `lib/src/theme/t_internal_material.dart:134` 上下文菜单按钮 - `lib/src/theme/t_internal_material.dart:951` 滚动条 两处分别补上 `_ =>` 与 `default:`。六个标准平台落到的分支与改动前完全一致, 未发布平台沿用移动端行为。同一文件的 75 行与 1008 行此前已有通配分支,本次与之对齐。 仓库 CI 不包含扩展 TargetPlatform 的 SDK,无法在构建中发现该问题,因此在 theme 组件测试中加入源码级穷尽性断言:扫描 `lib/` 下所有提及 TargetPlatform 的 switch 语句与 switch 表达式,要求存在通配分支。 Issue: Tencent#1218
Contributor
Web DemoAPK 下载 |
Contributor
Author
独立验证(非本机环境)@han-qiuyu 在
记录见 #1218 的验证回帖。我本地没有 ohos 扩展 SDK, @han-qiuyu 感谢验证。 |
|
等了好久了,啥时能正式修复啊! |
Collaborator
👀 在修了在修了,尽量这周再发一个版本。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

🤔 这个 PR 的性质是?
🔗 相关 Issue
关联讨论 #1218(已关闭;扩展平台上 TargetPlatform switch 非穷尽导致编译报错的问题在 develop 仍存在,本 PR 为独立修复)
同类历史问题:#436
💡 需求背景和解决方案
问题:
lib/src/theme/t_internal_material.dart中有两处 switch 只列出TargetPlatform的六个已发布枚举值,没有通配或兜底分支。TargetPlatform是可扩展的联合枚举,当 SDK 为它新增取值时(Flutter-OHOS 新增TargetPlatform.ohos),Dart 3 的穷尽性检查会直接判为编译错误,产物无法构建:lib/src/theme/t_internal_material.dart:134上下文菜单按钮(switch 表达式)lib/src/theme/t_internal_material.dart:951滚动条(switch 语句)方案:两处分别补上
_ =>与default:兜底分支。同一文件的 75 行与 1008 行此前已有通配分支,本次与之对齐:_menuButtons:桌面、iOS、macOS 保留各自分支,其余平台(android、fuchsia 及后续新增平台)落到通配分支的 Material 样式按钮,行为与改动前的 android/fuchsia 分支一致。buildScrollbar:linux、macOS、windows 保留RawScrollbar,其余平台(android、fuchsia、iOS 及后续新增平台)返回child,与改动前的行为一致。无 API 变化,不涉及 UI 或交互变动,因此无截图。
回归防护:仓库 CI 只有 flutter 3.32.0 与 latest,二者都不含扩展
TargetPlatform的 SDK,构建阶段无法暴露该问题,因此本次在test/components/theme/t_internal_material_test.dart中加入源码级穷尽性断言:扫描lib/下所有提及TargetPlatform的 switch 语句与 switch 表达式,要求存在通配分支。该测试文件已在component_test_manifest.dart中注册,随现有 CI 执行,不新增流水线步骤。📝 更新日志
fix(theme): 修复在扩展 TargetPlatform 的 Flutter SDK(如 Flutter-OHOS / OpenHarmony)下无法编译、构建失败的问题
本条 PR 不需要纳入 Changelog
☑️ 请求合并前的自查清单
type(<scope>?): 修改描述。示例:
fix(TBottomTabBar): 修复 iconText 模式底部溢出