79263425

Date: 2024-12-08 22:05:38
Score: 0.5
Natty:
Report link

So basically one of the problems was that I was initializing Firebase.initializeApp() only in production mode, not in debug mode. We have to move that function out of the if block, right after WidgetsFlutterBinding.ensureInitialized();.

But the problem persisted. Then, I downloaded my project from github in a different, new and clean directory - pasted my code - and it was working fine?

So basically, two folders, old with the git in it, and new and clean without git. Both have the same code, exactly the same, but old was giving me the same error, and new was running properly...

I didn't find the cause of this, and moved on.

Here is the proper code, with Firebase Testing Suite:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  if (kIsWeb || Platform.isIOS || Platform.isAndroid) {
    print("Running on Web/iOS/Android - Initializing Firebase...");
    await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform,
    );

    if (kDebugMode) {
      try {
        FirebaseFirestore.instance.useFirestoreEmulator('localhost', 8080);
        await FirebaseAuth.instance.useAuthEmulator('localhost', 9099);
        print(
            "Firebase initialized successfully - DEVELOPMENT -  for Web/iOS/Android.");
      } catch (e) {
        print(e);
      }
    } else {
      print(
          "Firebase initialized successfully - PRODUCTION -  for Web/iOS/Android.");
    }
  } else {
    print("Not running on Web/iOS/Android - Firebase functionality disabled.");
  }
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: xoxoxoco