Tushar Rai Tushar Rai - 6 months ago 28
Dart Question

Firebase throws error in an AngularDart project

Where I can find the Firebase (.firebaserc) file an AngularDart project.

Firebase writes the following file while project connection.

Writing configuration info to firebase.json...
Writing project information to .firebaserc...

firebase error

(anonymous function) Uncaught Unhandled exception:
ORIGINAL EXCEPTION: NoSuchMethodError: Class 'String' has no instance method
Receiver: "[DEFAULT]: Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app)."
Tried calling: _hasProperty("message")

It contains the code which initializes the firebase.

import 'dart:async';
import 'package:angular/angular.dart';
import 'package:firebase/firebase.dart' as fb;

class FirebaseService {
fb.User user;
fb.Auth _fbAuth;
fb.GoogleAuthProvider _fbGoogleAuthProvider;

FirebaseService() {
apiKey: "AIzaSyBOShlCgUeqTL99n32bjWdNlkH1111111",
authDomain: "my-app.firebaseapp.com",
databaseURL: "https://my-app.firebaseio.com",
storageBucket: "my-app.appspot.com",

_fbGoogleAuthProvider = new fb.GoogleAuthProvider();
_fbAuth = fb.auth();

void _authChanged(fb.User event) {
user = event;

Future signIn() async {
try {
await _fbAuth.signInWithPopup(_fbGoogleAuthProvider);
catch (error) {
print("$runtimeType::login() -- $error");

void signOut() {

Answer Source

If you have code in a service that should only be instantiated once, ensure that you only provide the service exactly once.

Provide such a service either only in

bootstrap(AppComponent, [...])

or alternatively only in

  providers: const [...])
class AppComponent {}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download