# FlutterError: 使用不包含 Navigator 的上下文请求导航操作

- **ID:** `flutter/navigator-operation-requested-with-a-context-that-does-not-include-a-navigator`
- **领域:** flutter
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

使用未位于 Navigator 小部件下的 BuildContext 调用 Navigator.push/pop/replace，通常来自无路由的覆盖层、对话框或 MaterialApp 构建之前。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Flutter 3.10 | active | — | — |
| Flutter 3.13 | active | — | — |
| Flutter 3.16 | active | — | — |

## 解决方案

1. ```
   Use Navigator.of(context, rootNavigator: true) to explicitly access the root navigator, or ensure the context is from a widget inside a MaterialApp/CupertinoApp.
   ```
2. ```
   Wrap the navigation call in a post-frame callback to ensure the widget tree is built and the context is valid.
   ```

## 无效尝试

- **** — The context may become stale or detach from the tree; the error persists if the widget is no longer in a route. (80% 失败率)
- **** — The root context is above the Navigator; navigator operations require a descendant context. (90% 失败率)
- **** — GlobalKey may still reference a disposed widget, yielding a context without a Navigator. (70% 失败率)
