I am using Riverpod for state management and want to set up Amplitude for tracking. I set up a provider using generators like so:
@riverpod
Amplitude amplitudeProvider(AmplitudeProviderRef ref) {
final Amplitude amplitude = Amplitude.getInstance();
amplitude.init(Env.amplitudeApiKey);
return amplitude;
}
But when I try to read it with
final amplitude = ref.read(amplitudeProvider);
I get the error
The argument type 'Amplitude Function(ProviderRef)' can't be assigned to the parameter type 'ProviderListenable'.
When I set up the provider manually with code-generation everything works. But since you shouldn’t mix generated and not generated providers, I am kind of in a pickle. Does anyone understand where this is coming from?
Works like this:
final amplitudeProvider = Provider<Amplitude>((ref) {
final Amplitude amplitude = Amplitude.getInstance();
amplitude.init(Env.amplitudeApiKey);
return amplitude;
});