Tushar Rai
Tushar Rai

Reputation: 2519

Dart wrapper library for the new Firebase version ^4.0.0 error

Dart wrapper library for the new Firebase. I have updated the firebase dependency in my AngularDart project from version ^3.0.0 to ^4.0.0, but it's showing an error: Undefined class'fb.AuthEvent'.`

firebase_service.dart

  import 'dart:async';
  import 'package:angular2/core.dart';
  import 'package:firebase/firebase.dart' as fb;
  import 'package:angular_components/angular_components.dart';

@Injectable()
  class FirebaseService {
  fb.User user;
  fb.Auth _fbAuth;
  fb.GoogleAuthProvider _fbGoogleAuthProvider;
  fb.Database _fbDatabase;
  fb.Storage _fbStorage;
  fb.DatabaseReference _fbRefMessages;

 FirebaseService() {
   fb.initializeApp(
   apiKey: ".......",
   authDomain: ".....",
   databaseURL: ".....",
   storageBucket: ".....",
 );

_fbGoogleAuthProvider = new fb.GoogleAuthProvider();
_fbAuth = fb.auth();
_fbAuth.onAuthStateChanged.listen(_authChanged);
}

void _authChanged(fb.AuthEvent event) {
 user = event.user;
}

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

 void signOut() {
  _fbAuth.signOut();
  }
 }`

Upvotes: 0

Views: 96

Answers (1)

Hadrien Lejard
Hadrien Lejard

Reputation: 5924

From the Firebase package Changelog

Breaking changes

- The value in Auth.onAuthStateChanged is now User. AuthEvent has been 
removed.

And from the new Documentation, onAuthStateChanged is a Stream<User>

So you should change your _authChanged function to

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

Upvotes: 1

Related Questions