fix(home): Scrollbar+SingleChildScrollView primary:true (no ScrollPosition runtime error); docs: runtime issues in TODO §9

This commit is contained in:
2026-08-01 01:53:05 +08:00
parent 9608e8b9fb
commit b49fb59db4
3 changed files with 30 additions and 4 deletions

23
TODO.md
View File

@@ -225,3 +225,26 @@ f8a90ad 基线
flutter build web # 目标:无 error生成 build/web flutter build web # 目标:无 error生成 build/web
flutter run -d chrome # 目标:能打开、首页/商品/购物车/结账流程跑通 flutter run -d chrome # 目标:能打开、首页/商品/购物车/结账流程跑通
``` ```
---
## 9. 运行时问题(应用已能运行,以下为后续优化,非阻塞)
应用 `flutter run -d chrome` 已成功启动并加载首页/API 数据/数据库。控制台有以下运行时警告/异常:
### 9.1 Scrollbar 缺 ScrollPosition真实影响滚动条显示
4 个 `Scrollbar(` 未配 `controller`,新版 Flutter 的 Scrollbar 找不到 ScrollPosition
- `lib/pages/home.dart:101` — ✅ 已修:给 `SingleChildScrollView``primary: true`
- `lib/pages/blog.dart:24` — 子是 `DesktopBlog`(自定义组件)
- `lib/pages/download.dart:63` — 子是 `DesktopDownloadApps`(自定义组件)
- `lib/widgets/desktop/shop.dart:137` — 包裹 `NotificationListener`
后 3 处的子是自定义组件,需让内部 ListView/ScrollView 暴露 controller`primary: true`)或 Scrollbar 改用 `NotificationListener` 关联。**仅影响滚动条渲染,不影响内容加载/显示。**
### 9.2 CustomersLogo setState-after-dispose小 bug
`lib/widgets/desktop/desktop_customers_logo.dart``Timer.periodic`(每 10s 刷新 logo未在 `dispose()``cancel()`,组件卸载后 timer 仍触发 `setState`。建议在 `dispose``timer?.cancel()`。**热重载时易触发,干净启动偶发。**
### 9.3 `_business` LateInitializationError热重载假象
`_business` 是店铺页面组件(`shop_promote.dart`/`shop.dart` 等)的 `late Business` 字段。热重载重建 widget 树时字段状态丢失触发,**干净启动(浏览器刷新 Cmd+R不会出现**。
> **验证方式**:在浏览器里 Cmd+R 刷新页面而非热重载9.2/9.3 类异常应消失,仅剩 9.1 的滚动条警告。

View File

@@ -5,15 +5,17 @@
# ./build_web.sh run # 构建并在 Chrome 中运行调试版 # ./build_web.sh run # 构建并在 Chrome 中运行调试版
# #
# 说明: # 说明:
# - 必须 --no-tree-shake-icons: 项目中有 24 处 IconData(codePoint) 使用 # - 构建(release)必须 --no-tree-shake-icons: 项目中有 24 处 IconData(codePoint)
# 来自 JSON/API 的动态 code point(非 const), icon tree-shaking 无法处理。 # 使用来自 JSON/API 的动态 code point(非 const), icon tree-shaking 无法处理。
# 注意: --no-tree-shake-icons 仅 build 支持; flutter run(debug)不做 tree-shaking,
# 因此 run 分支不带该 flag。
# - Dart SDK: 本地 Flutter 3.29.3 / Dart 3.7.2(未升级全局 SDK)。 # - Dart SDK: 本地 Flutter 3.29.3 / Dart 3.7.2(未升级全局 SDK)。
set -e set -e
cd "$(dirname "$0")" cd "$(dirname "$0")"
if [ "$1" = "run" ]; then if [ "$1" = "run" ]; then
echo ">>> flutter run -d chrome --no-tree-shake-icons" echo ">>> flutter run -d chrome"
flutter run -d chrome --no-tree-shake-icons flutter run -d chrome
else else
echo ">>> flutter build web --no-tree-shake-icons" echo ">>> flutter build web --no-tree-shake-icons"
flutter build web --no-tree-shake-icons flutter build web --no-tree-shake-icons

View File

@@ -101,6 +101,7 @@ class HomeState extends State<Home> {
desktop: Scrollbar( desktop: Scrollbar(
thumbVisibility: true, thumbVisibility: true,
child: SingleChildScrollView( child: SingleChildScrollView(
primary: true,
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [