skip to Main Content

I am devoloping a multi platform app using flutter for android and ios. Now I am trying to connect my app with Firebase. I did every necessary steps including, adding google_services.json, adding firebase core, auth, core web, cloud firestore. But for some reason my app stops at the line await Firebase.initializeApp();. its shows the error Error: Assertion failed:.

Here is my main.dart

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'features/auth/welcome_screen.dart';

Future main() async {
  WidgetsFlutterBinding.ensureInitialized();
  print("////////////////////////////////");
  await Firebase.initializeApp();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'UniCompanion',
      debugShowCheckedModeBanner: false,
      home: WelcomeScreen(),
    );
  }
}

and here is the error:

Error: Assertion failed:
file:///C:/Users/rudro/AppData/Local/Pub/Cache/hosted/pub.dev/firebase_core_web-2.4.0/li
b/src/firebase_core_web.dart:256:11
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/priva
te/ddc_runtime/errors.dart 266:49  throw_
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/priva
te/ddc_runtime/errors.dart 29:3    assertFailed
packages/firebase_core_web/src/firebase_core_web.dart 256:18
initializeApp
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch
/async_patch.dart 45:50            <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1660:54       
runUnary
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 147:18 
handleValue
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 767:44 
handleValueCallback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 796:13 
_propagateToListeners
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 567:5  
[_completeWithValue]
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future.dart 528:22      
<fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1660:54       
runUnary
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 147:18 
handleValue
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 767:44 
handleValueCallback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 796:13 
_propagateToListeners
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 567:5  
[_completeWithValue]
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 640:7  
callback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 
40:11                              _microtaskLoop
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 
49:5                               _startMicrotaskLoop
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch
/async_patch.dart 166:15           <fn>

Please help me with this.

I tried to add all dependencies such as adding these line in pubspec.yaml file

  firebase_auth: ^4.5.0
  cloud_firestore: ^4.6.0
  firebase_analytics: ^10.3.0
  firebase_core: ^2.11.0
  firebase_core_web: ^2.4.0

2

Answers


  1. It looks like you’re missing the configuration for the web app, which needs to be inside JavaScript file as shown in this documentation on initializing the Flutter SDK for Firebase for a web app.

    Honestly, I’d nowadays recommend putting the initialization in the Dart code – by following the setup instructions in adding Firebase to your Flutter app.

    Login or Signup to reply.
  2. In your main.dart in the void main(runApp()) section add this and try

    await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform,
    );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search