I want to pass multiple arguments to a riverpod provider and make network requests accordingly as below
@riverpod
class FetchProducts extends _$FetchProducts {
@override
Future<List<Product>> build({
required String? specificProductId,
required String? clientUid,
}) async {
if (specificProductId != null) {
// Network request-1
}
} else if (clientUid != null && clientUid != '') {
// Network request-2
}
else {
// Network request-3
}
}
Console shows below when it is initialized first with both parameters null (i.e. Network request-3 would have run). Note the null in the parenthesis for arguments.
Provider fetchProductsProvider:FetchProductsProvider#6e9e5(null) was
initialized with AsyncLoading<List>()
When another widget makes another network request with a non-null clientUID (i.e. Network request-2) below is what we get in console. Note the null in the place of arguments.
Provider fetchProductsProvider:FetchProductsProvider#0eacb(null) was
initialized with AsyncLoading<List>() Provider
fetchProductsProvider:FetchProductsProvider#6e9e5(null) was disposed
Please suggest correct way of passing multiple arguments to riverpod provider so that both the network requests with different arguments are cached and not disposed.