networkServiceProvider top-level property

AutoDisposeProviderFamily<NetworkService, String> networkServiceProvider
final

Implementation

final networkServiceProvider =
    Provider.family.autoDispose<NetworkService, String>((ref, query) {
  // An object from package:dio that allows cancelling http requests
  final cancelToken = CancelToken();
  // When the provider is destroyed, cancel the http request
  ref.onDispose(() => cancelToken.cancel());
  final _apiKey = ref.read(apiKeyProvider).state;
  final _url = ref.read(urlConstantsProvider).getUrlForQuery(
        query: query,
        kMapBoxKey: _apiKey,
      );
  ref.maintainState = true;
  return NetworkService(dio: Dio(), url: _url);
});