I having been using riverpod for a long time now. As is programing, some times you come across a problem i feel like WTF.
I have this basic line:
@riverpod
FutureOr<List<PlaceAutocomplete>> placeAutocompleteState(
PlaceAutocompleteStateRef ref,
) {
final repoProvider = ref.watch(mapRepoProvider);
debugPrint("repoProvider: $repoProvider");
final query = ref.watch(placeAutocompleteQueryProvider);
debugPrint("my query: $query");
return query.fold(
() => const [],
(query) => ref.watch(getPlaceAutocompleteProvider(query).future),
);
}
The line debugPrint("repoProvider: $repoProvider");
is not printing, which means that ref.watch(mapRepoProvider)
is not returning. I put that in there because I was wondering at some other part of the code why I was getting no result. If I remove ref.watch(mapRepoProvider)
I can see the print of debugPrint("my query: $query");
mapRepoProvider
is defined as follows:
part 'map_repo.g.dart';
@Riverpod(keepAlive: true)
MapRepo mapRepo(MapRepoRef ref) {
return MapRepo(
remoteDataSource: ref.watch(mapRemoteDataSourceProvider),
);
}
class MapRepo {
MapRepo({
required this.remoteDataSource,
});
final MapRemoteDataSource remoteDataSource;
Future<List<PlaceAutocomplete>> getPlaceAutocomplete(
String placeName, {
CancelToken? cancelToken,
}) async {
debugPrint("placeautocomplete");
final autocomplete =
await remoteDataSource.getPlaceAutocomplete(placeName, cancelToken: cancelToken);
return autocomplete.map((item) => item.toDomain()).toList();
}
}
ref.watch(otherProvider)
works fine at other places with other providers. I cannot understand why this one specifically is blocking.
I had a Dio class which was defined as follows:
@Riverpod(keepAlive: true)
Dio googleMapDio(GoogleMapDioRef ref) {
final logger = Logger('Dio')..level = Level.FINEST;
final sub = logger.onRecord.listen((record) {
debugPrint('${record.level.name}: ${record.time}: ${record.message}');
});
ref.onDispose(sub.cancel);
return Dio()
..options = BaseOptions(
baseUrl: GoogleMapApiConfig.googleMapBaseUrl,
connectTimeout: MainApiConfig.connectTimeout,
receiveTimeout: MainApiConfig.receiveTimeout,
)
..interceptors.addAll([
//order is necessary.
ContentTypeInterceptor(),
ApiKeyInterceptor(),
//ref.watch(sessionTokenInterceptorProvider),
ErrorInterceptor(),
LogInterceptor(logPrint: logger.finest),
]);
}
The logger
was causing the problem but I don't know why. After removing it, it works