Dartz interface invalid override

156 views Asked by At

I am currently setting up a phone number verification in flutter with the dartz package. My firebase_auth_facade.dart inherits from my i_auth_facade.dart but when I try to set up the phonenumber verification functions I get the error:

"FirebaseAuthFacade.verifyAndLinkPhoneNumber' ('Future<Either<AuthFailure, Unit>> Function(String, String)') isn't a valid override of 'IAuthFacade.verifyAndLinkPhoneNumber' ('Future<Either<AuthFailure, Unit>> Function({String smsCode, String verificationId})')."

Here's my code:

i_auth_facade.dart:

Future<Either<AuthFailure, Unit>> verifyAndLinkPhoneNumber({
  @required String verificationId,
  @required String smsCode,
});

firebase_auth_facade.dart:

@override
Future<Either<AuthFailure, Unit>> verifyAndLinkPhoneNumber(
    String verificationId, String smsCode) async {
  try {
    PhoneAuthCredential phoneAuthCredential = PhoneAuthProvider.credential(
        verificationId: verificationId, smsCode: smsCode);
    if (phoneAuthCredential == null) {
      return left((const AuthFailure.cancelledByUser()));
    }
    await _firebaseAuth.currentUser.linkWithCredential(phoneAuthCredential);
    return right(unit);
    } on FirebaseAuthException catch (_) {
    return left(const AuthFailure.serverError());
  }
}

Does anyone have an idea why the latter isn't a valid override? Thanks!

1

There are 1 answers

0
Andi On

Got it. I forgot to wrap the constructor in curly brackets. firebase_auth_facade.dart should look like this:

@override
Future<Either<AuthFailure, Unit>> verifyAndLinkPhoneNumber({
@required String smsCode,
@required String verificationId,
}) async {
try {
  final verificationIdStr = verificationId;
  final smsCodeStr = smsCode.getOrCrash();
  PhoneAuthCredential phoneAuthCredential = PhoneAuthProvider.credential(
      verificationId: verificationIdStr, smsCode: smsCodeStr);
  if (phoneAuthCredential == null) {
    return left((const AuthFailure.cancelledByUser()));
  }
  await _firebaseAuth.currentUser.linkWithCredential(phoneAuthCredential);
  return right(unit);
} on FirebaseAuthException catch (_) {
  return left(const AuthFailure.serverError());
}