# FlutterError: ScrollController 未附加到任何滚动视图。

- **ID:** `flutter/scroll-controller-not-attached`
- **领域:** flutter
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

ScrollController 在释放后使用，或在附加到 Scrollable 小部件之前使用。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.10.0 | active | — | — |
| 3.13.0 | active | — | — |
| 3.16.0 | active | — | — |
| 3.22.0 | active | — | — |

## 解决方案

1. ```
   Ensure ScrollController is created once (e.g., in initState) and disposed in dispose(). Use a StatefulWidget.
   ```
2. ```
   Use ScrollController.keepScrollOffset() or check _controller.hasClients before accessing scroll position.
   ```
3. ```
   Switch to ScrollableState or use NotificationListener<ScrollNotification> to avoid explicit controller management.
   ```

## 无效尝试

- **** — Disposing the controller before it's attached prevents any scrolling functionality. (45% 失败率)
- **** — Creates memory leaks and detached controllers that accumulate. (30% 失败率)
- **** — Does not fix the underlying lifecycle issue; scrolling will silently fail. (25% 失败率)
