# AssertionError: 在发布模式下 '!_debugAllowCreation' 不为真

- **ID:** `flutter/release-mode-debug-assert`
- **领域:** flutter
- **类别:** assertion_error
- **验证级别:** ai_generated
- **修复率:** 72%

## 根因

一个仅限调试的断言检查小部件创建权限，在发布模式下被触发，因为本应禁用的代码路径（例如调试覆盖层或检查器）由于构建标志配置错误或遗留的调试代码仍然处于活动状态。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Flutter 3.13.0 | active | — | — |
| Flutter 3.22.0 | active | — | — |
| Dart 3.1.0 | active | — | — |

## 解决方案

1. ```
   确保调试特定代码（如 debugPaintSizeEnabled 或自定义调试覆盖层）包装在 'assert(() { ... }());' 中或使用 'kReleaseMode' 条件编译。示例：
  if (kDebugMode) {
    // 仅调试的小部件创建
  }
   ```
2. ```
   运行 'flutter clean' 并使用 'flutter build apk --release' 重新构建，确保没有残留的调试工件。
   ```
3. ```
   检查可能注入调试小部件的第三方包；更新它们或通过包配置排除调试功能。
   ```

## 无效尝试

- **Add '--debug' flag to the build command to avoid release mode** — The error occurs in release mode; using debug mode bypasses the issue but doesn't solve the root cause for production builds. (70% 失败率)
- **Remove all assert() statements from the codebase** — Assertions are stripped in release mode by default; the error is from Flutter's internal assertions, not user code. (90% 失败率)
- **Set '--no-sound-null-safety' to suppress the assertion** — Null safety is unrelated; the assertion is about widget creation permissions, not null checks. (80% 失败率)
