I am using riverpod annotation and stuck here.
@riverpod
ShopRepository shopRepository(ShopRepositoryRef ref) => ShopRepositoryImpl(dio: authDio(), managerLocalStorage: ref.watch(managerLocalStorageImplProvider));
managerLocalStorageImplProvider
part says,
The argument type 'AutoDisposeNotifierProviderImpl<ManagerLocalStorageImpl, ManagerLocalStorageState>' can't be assigned to the parameter type 'ProviderListenable<ManagerLocalStorage>'.
Here'are other codes:
// This class doesn't have riverpod annotation.
class ShopRepositoryImpl extends ShopRepository {
ShopRepositoryImpl({required Dio dio, required ManagerLocalStorage managerLocalStorage}) {
_apiClient = ShopApiClient(dio, baseUrl: Constants.shopDomain);
_localStorage = managerLocalStorage;
}
late final ShopApiClient _apiClient;
late final ManagerLocalStorage _localStorage;
}
@riverpod
class ManagerLocalStorageImpl extends _$ManagerLocalStorageImpl implements ManagerLocalStorage {
late final FlutterSecureStorage _storage;
@override
ManagerLocalStorageState build() {
Log(usePretty: false).d("printed!! build build build");
_storage = ref.read(secureStorageProvider);
return ManagerLocalStorageState();
}
...
}
How can I fix this issue?
What I got to know is the build()'s return Type will be the second type of generated Provider's generic. And the generated provider from managerLocalStorageImpl is AutoDisposeNotifierProviderImpl but the argument expects ProviderListenable and the generic has only one type. I don't know even it's possible to pass like this or not.
I am trying to do MVVM pattern. So, it would be appreciated if you can suggest some structured code snippets.
Riverpod seems it is global and can be access from everywhere like against to SOLID. Is there any way to prevent it?
AutoDisposeNotifierProviderImpl
doesn't conflict withProviderListenable
ref.watch(managerLocalStorageImplProvider)
has typeManagerLocalStorageState
, which is not a subclass ofManagerLocalStorage
.if you write like this, dart analyzer would recognize the error