How to add provider dependency of type of AsyncNotifierProvider?

71 Views Asked by At

I've a riverpod provider called storedDataStateProvider that I'd like to add it as dependency for authServiceProvider so when AuthService is build StoredDataState would be already available, but riverpod_generador is not even letting me compile AuthService throwing an annotation error (shown below).

stored_data_state.dart:

@Riverpod(keepAlive: true)
class StoredDataState extends _$StoredDataState {
    ...
}

auth_service.dart:

@Riverpod(dependencies: [storedDataStateProvider])
class AuthService extends _$AuthService {
    ...
}

the error:

line 1, column 895 of package:../auth_service.dart: Could not resolve annotation for `class AuthService extends AutoDisposeNotifier<dynamic>`.
  ╷
1 │ @Riverpod(dependencies: [storedDataStateProvider])
  │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I've work with other riverpod dependencies in my project but they refer to types of AutoDisposeProvider that works but is it possible to refer to a riverpod dependency of AsyncNotifierProvider which is the one generated from riverpod class?

1

There are 1 best solutions below

0
On

Apparently you can use the class/function name and not the generated provider that it will work. This "issue" is marked to be worked on github (see link below).

@Riverpod(dependencies: [StoredDataState])

https://github.com/rrousselGit/riverpod/issues/2998