# FirebaseException: 名为 '[DEFAULT]' 的 Firebase 应用已存在

- **ID:** `flutter/firebase-app-not-initialized`
- **领域:** flutter
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

多次调用 Firebase.initializeApp() 而未检查默认应用是否已初始化。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Flutter 3.22.0 | active | — | — |
| firebase_core 2.27.0 | active | — | — |
| firebase_auth 4.17.0 | active | — | — |

## 解决方案

1. ```
   Check if Firebase is already initialized before calling initializeApp: `if (Firebase.apps.isEmpty) { await Firebase.initializeApp(); }`.
   ```
2. ```
   Initialize Firebase only once in the main() function before runApp: `WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); runApp(MyApp());`.
   ```
3. ```
   Use a singleton pattern to wrap Firebase initialization and prevent duplicate calls.
   ```

## 无效尝试

- **** — Each call attempts to reinitialize, causing the 'already exists' error on subsequent calls. (90% 失败率)
- **** — Ignoring the error may lead to duplicate Firebase instances and unexpected behavior. (80% 失败率)
- **** — Firebase apps cannot be deleted programmatically; this approach is not supported. (95% 失败率)
