求助:Flutter项目运行Windows平台时出现DefaultFirebaseOptions未配置报错如何解决
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.jsonfile (generated by Firebase Console or FlutterFire CLI) is placed inwindows/runner/Resources/of your project. The CLI should handle this, but if not, copy it manually. - You have the
firebase_coredependency in yourpubspec.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 cleanto 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

