flutterfirebasedartfirebase-authentication

Flutter FirebaseError: Firebase: firebase.auth() takes either no argument or a Firebase App instance. (app/invalid-app-argument)


I have created a firebase email/password auth and it was working fine until today. Sign up and sign in stopped working and I tried flutter clean and re running it. The code hasnt changed as I tried reverting to an older version of the app and it still gave the same error. Here are some more details: FirebaseError: Firebase: firebase.auth() takes either no argument or a Firebase App instance. (app/invalid-app-argument).

This is my button

ElevatedButton(
  style: buttonStyle,
  onPressed: () async {
    if (_formKey.currentState!.validate()) {
      try {
        final credential = await FirebaseAuth.instance
            .signInWithEmailAndPassword(
          email: _emailController.text,
          password: _passwordController.text,
        ).then((_) {
          Navigator.pushReplacementNamed(context, '/timeline');
        });
      } on FirebaseAuthException catch (e) {
        if (e.code == "invalid-email") {
          showDialog(
            context: context,
            builder: (context) => ErrorMessage("Invalid email"),
          );
        } else if (e.code == 'user-not-found') {
          showDialog(
            context: context,
            builder: (context) => ErrorMessageWithRoute(
              "Email not registered",
              "/signup",
            ),
          );
        } else if (e.code == 'wrong-password') {
          showDialog(
            context: context,
            builder: (context) => ErrorMessage("Wrong password"),
          );
        }
      } catch (e) {
        showDialog(
          context: context,
          builder: (context) => ErrorMessage(
            "There was an error please contact us or try again ${e}",
          ),
        );
      }
    }
  },
  child: const Text("Sign in"),
);

The catchall at the end is what is running and telling me the error. Here are my firebase options I removed all the values but left the keys for security:

// 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:
        throw UnsupportedError(
          'DefaultFirebaseOptions have not been configured for macos - '
          'you can reconfigure this by running the FlutterFire CLI again.',
        );
      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.',
        );
    }
  }

  static const FirebaseOptions web = FirebaseOptions(
    apiKey: ,
    appId: ,
    messagingSenderId: ,
    projectId: ,
    authDomain: ,
    storageBucket: ,
    measurementId: ,
  );

  static const FirebaseOptions android = FirebaseOptions(
    apiKey: ,
    appId: ,
    messagingSenderId: ,
    projectId: ,
    storageBucket: ,
  );

  static const FirebaseOptions ios = FirebaseOptions(
    apiKey: ,
    appId: ,
    messagingSenderId: ,
    projectId: ,
    storageBucket: ,
    androidClientId:
        ,
    iosClientId:
        ,
    iosBundleId: ,
  );
}

The domain I am running it on is localhost 5000 and I allowed it in the google cloud apis and services

main.dart

// Flutter widgets
import 'package:flutter/material.dart';

// Pages
import 'package:fbla_lettering_point_app/Pages/User/timeline.dart';
import 'package:fbla_lettering_point_app/Pages/signup.dart';
import 'package:fbla_lettering_point_app/Pages/login.dart';
import 'package:fbla_lettering_point_app/Pages/User/profile.dart';
import 'package:fbla_lettering_point_app/Pages/verify_email_page.dart';
import 'package:fbla_lettering_point_app/Pages/Admin/admin_timeline.dart';

// DB/Auth
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
import 'package:firebase_auth/firebase_auth.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'FBLA Lettering Points',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      routes: <String, WidgetBuilder>{
        '/signin': (context) => const SignInPage(),
        '/signup': (context) => const SignUpPage(),
        '/timeline': (context) => const Timeline(),
        '/profile': (context) => const Profile(),
        '/verify': (context) => const VerifyEmailPage(),
      },
      home: const SignInPage(),
    );
  }
}



Solution

  • I figured out the issue, I tried updating my package numbers in pub.dev and this worked.