Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid closing externally created http.Client in NetworkTileProvider #2012

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/src/layer/tile_layer/tile_provider/network_tile_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class NetworkTileProvider extends TileProvider {
super.headers,
Client? httpClient,
this.silenceExceptions = false,
}) : _httpClient = httpClient ?? RetryClient(Client());
}) : _isInternallyCreatedClient = httpClient == null,
_httpClient = httpClient ?? RetryClient(Client());

/// Whether to ignore exceptions and errors that occur whilst fetching tiles
/// over the network, and just return a transparent tile
Expand All @@ -45,8 +46,14 @@ class NetworkTileProvider extends TileProvider {
/// Long living client used to make all tile requests by
/// [MapNetworkImageProvider] for the duration that this provider is
/// alive
///
/// Not automatically closed if created externally and passed as an argument
/// during construction.
final Client _httpClient;

/// Whether [_httpClient] was created on construction (and not passed in)
final bool _isInternallyCreatedClient;

/// Each [Completer] is completed once the corresponding tile has finished
/// loading
///
Expand Down Expand Up @@ -76,7 +83,8 @@ class NetworkTileProvider extends TileProvider {
if (_tilesInProgress.isNotEmpty) {
await Future.wait(_tilesInProgress.values.map((c) => c.future));
}
_httpClient.close();
if (_isInternallyCreatedClient) _httpClient.close();

super.dispose();
}
}
Loading