Why it is showing error for DefaultFirebaseOptions.currentplatform?
I'm trying to connect flutter app to firebase and I implemented dependencies correctly,but showing error on DefaultFirebaseOptions.currentolatform.
I just ran into the same problem.  It happens if you use a tool (like following the Firebase setup instructions) that will automatically create firebase_options.dart for you.  The tool creates it in {project_root}/lib/ right next to main.dart, but if you try to initialize Firebase in a different library like I did, it can't find DefaultFirebaseOptions.
I had added the dependency for firebase_core in the library, but what I didn't realize was that DefaultFirebaseOptions is actually defined in the firebase_options.dart file that is created and updated for you by the flutterfire configure command.  It's a class with properties unique to your Firebase app.

So, you can either add a dependency on the root project library to the .yaml for the sub project.
OR
Just initialize Firebase in the main.dart file like the documention mentions (but I initially took as only a suggestion).
import 'package:yourproject/firebase_options.dart'; // <-- Need this import
import 'package:firebase_core/firebase_core.dart';
Future<void> main() async {
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  runApp(const MainAppWidget());
}
Note:  If you are missing `firebase_options.dart` completely, take a look at Step 2 in the Firebase Flutter documentation here .  TL;DR: try running flutterfire configure in your project directory which will generate the file under `{project root}/lib`
I was facing the same issue after checking in the repository of Firebase. found that that has created a separated class for that you can take reference from here. Hope it will work.
// Copyright 2022, the Chromium project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// File generated by FlutterFire CLI.
// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
import 'package:flutter/foundation.dart'
    show defaultTargetPlatform, kIsWeb, TargetPlatform;
/// Default [FirebaseOptions] for use with your Firebase apps.
///
/// Example:
/// ```dart
/// import 'firebase_options.dart';
/// // ...
/// await Firebase.initializeApp(
///   options: DefaultFirebaseOptions.currentPlatform,
/// );
/// ```
class DefaultFirebaseOptions {
  static FirebaseOptions get currentPlatform {
    if (kIsWeb) {
      return web;
    }
    switch (defaultTargetPlatform) {
      case TargetPlatform.android:
        return android;
      case TargetPlatform.iOS:
        return ios;
      case TargetPlatform.macOS:
        return macos;
      case TargetPlatform.windows:
        throw UnsupportedError(
          'DefaultFirebaseOptions have not been configured for windows - '
          'you can reconfigure this by running the FlutterFire CLI again.',
        );
      case TargetPlatform.linux:
        throw UnsupportedError(
          'DefaultFirebaseOptions have not been configured for linux - '
          'you can reconfigure this by running the FlutterFire CLI again.',
        );
      default:
        throw UnsupportedError(
          'DefaultFirebaseOptions are not supported for this platform.',
        );
    }
  }
Reference github link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With