You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:Flutter项目运行Windows平台时出现DefaultFirebaseOptions未配置报错如何解决

Fix: "DefaultFirebaseOptions have not been configured for windows" Error in Flutter

Hey, I’ve run into this exact issue before when getting Firebase up and running on Flutter Windows—let me walk you through the steps to fix it:

1. Re-run FlutterFire CLI with Windows selected

First, make sure you have the FlutterFire CLI installed. If you don’t, grab it with:

dart pub global activate flutterfire_cli

Head to your project’s root folder in the terminal, then run:

flutterfire configure

When the CLI prompts you to select platforms, don’t forget to check Windows (along with any other platforms you’re using). This command will regenerate your firebase_options.dart file with the correct Windows-specific config.

2. Verify the generated config file

Check your lib/firebase_options.dart file—you should see a section for Windows that looks like this:

static const FirebaseOptions windows = FirebaseOptions(
  apiKey: "your-api-key-here",
  appId: "your-app-id-here",
  messagingSenderId: "your-sender-id-here",
  projectId: "your-project-id-here",
  storageBucket: "your-storage-bucket-here",
);

If this section is missing, the CLI didn’t process Windows—re-run flutterfire configure and double-check you selected the Windows platform.

3. Make sure Firebase initializes correctly

In your main.dart, confirm you’re using the platform-aware initialization. Your main function should look something like this:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  runApp(const MyApp());
}

The currentPlatform getter automatically picks the right config for Windows when running on that platform.

4. Double-check Windows-specific setup details

If the above steps don’t resolve the error, verify these two things:

  • The firebase_app_id.json file (generated by Firebase Console or FlutterFire CLI) is placed in windows/runner/Resources/ of your project. The CLI should handle this, but if not, copy it manually.
  • You have the firebase_core dependency in your pubspec.yaml:
    dependencies:
      flutter:
        sdk: flutter
      firebase_core: ^2.15.0 # Use the latest version available
    

Run flutter pub get after updating dependencies.

Final cleanup & rebuild

  • Run flutter clean to clear any cached build files
  • Rebuild your Windows app with flutter run -d windows

That should get rid of the error and let Firebase work on Windows smoothly.

内容的提问来源于stack exchange,提问作者Faraz Riaz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 01:07:36