1

i have a working app with an "old" firebase auth widget. Now the auth was updated and nothing is working anymore.

can you help me fixing it????

This is the whole widget:

import 'package:firebase_auth/firebase_auth.dart';

class AuthService {
  final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;

  // ignore: deprecated_member_use
  Stream<String> get onAuthStateChanged => _firebaseAuth.onAuthStateChanged.map(
        (User user) => user?.uid,
      );

  //Email & Password Sign up
  Future<String> createUserWithEmailAndPassword(
      String email, String password, String name) async {
    final currentUser = await _firebaseAuth.createUserWithEmailAndPassword(
      email: email,
      password: password,
    );

    //Update the Username
    var userUpdateInfo = UserUpdateInfo();
    userUpdateInfo.displayName = name;
    await currentUser.updateProfile(userUpdateInfo);
    await currentUser.reload();
    return currentUser.uid;
  }

//Email Password Sign In
  Future<String> signInWithEmailAndPassword(
      String email, String password) async {
    return (await _firebaseAuth.signInWithEmailAndPassword(
            email: email, password: password))
        .user
        .uid;
  }

//Sign Out
  signOut() {
    return _firebaseAuth.signOut();
  }
}

And this part from widget is not working anymore:

    //Update the Username
    var userUpdateInfo = UserUpdateInfo();
    userUpdateInfo.displayName = name;
    await currentUser.updateProfile(userUpdateInfo);
    await currentUser.reload();
    return currentUser.uid;

Here are the Errors:

error: The method 'UserUpdateInfo' isn't defined for the type 'AuthService'. error: The method 'updateProfile' isn't defined for the type 'UserCredential'. error: The method 'reload' isn't defined for the type 'UserCredential'. error: The getter 'uid' isn't defined for the type 'UserCredential'.

2 Answers2

2

I recommend looking at the upgrade guide for FlutterFire, and at the updated reference documentation the firebase_auth library.

For example, the updateProfile method and reload method and the uid property are now defined on the User object.

The same User object also has an updateProfile method, which takes the displayName as an optional, named parameter.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
0

You should decrease the version of library or refactor your code by new documention of this library.

Islomkhuja Akhrarov
  • 1,277
  • 9
  • 19