0

We are implementing Hexagonal Architecture in our Flutter application. For authentication we created a interface which will be later inherited by the authentication repository.

Two functions uses generic parameter: one is for social signup what can change up to the authentication service(in our case, Amplify Cognito), and the other one receive user attributes which can be changeable(again, up to the service).

abstract class AuthRepository {
  Future<List<T>> fetchUserAttributes<T>();
  Future<bool> signInWithSocialWebUI<T>({required T provider});
}

Well, it is not a problem to override them in the repository, but i'm getting an annoying error at code level: enter image description here

As you can see, types differ on *(which i can't understand since it means pointers on C++): The argument type 'AuthProvider' can't be assigned to the parameter type 'AuthProvider*'.dartargument_type_not_assignable.

In this case, this error comes with:

@override
  Future<bool> signInWithSocialWebUI<AuthProvider>(
      {required AuthProvider provider}) async {
    try {
      SignInResult result =
          await _authCategory.signInWithWebUI(provider: provider);
      return result.isSignedIn;
    } on AmplifyException catch (error) {
      // TODO: Catch error for analytics, not required for frontend.
      return false;
    }
  }

In other case We get: A value of type 'List<AuthUserAttribute*>*' can't be assigned to a variable of type 'List<AuthUserAttribute>'. Try changing the type of the variable, or casting the right-hand type to 'List<AuthUserAttribute>'.dartinvalid_assignment.

And the code is:

  @override
  Future<List<AuthUserAttribute>>
      fetchUserAttributes<AuthUserAttribute>() async {
    try {
      List<AuthUserAttribute> result =
          await _authCategory.fetchUserAttributes();
      return result;
    } on AmplifyException catch (error) {
      // TODO: Catch error for analytics, not required for frontend.

    }
  }

The common denominator in both cases is the generic type with which I defined these functions.

This problem just happens when i use generics, no in other cases; it affects cause if we want to change to a Firebase provider i would want to change the social authentication provider type.

How can I solve this missmatching problem?

Thank you very much.

SalahAdDin
  • 1,432
  • 14
  • 42

0 Answers0