Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 520d3ac

Browse files
authored
fix: avoid closing externally created Dio client in CancellableNetworkTileProvider (#13)
1 parent 388e94d commit 520d3ac

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/src/tile_provider.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,23 @@ base class CancellableNetworkTileProvider extends TileProvider {
5656
super.headers,
5757
Dio? dioClient,
5858
this.silenceExceptions = false,
59-
}) : _dioClient = dioClient ?? Dio();
59+
}) : _isInternallyCreatedClient = dioClient == null,
60+
_dioClient = dioClient ?? Dio();
6061

6162
/// Whether to ignore exceptions and errors that occur whilst fetching tiles
6263
/// over the network, and just return a transparent tile
6364
final bool silenceExceptions;
6465

6566
/// Long living client used to make all tile requests by [CancellableNetworkImageProvider]
6667
/// for the duration that this provider is alive
68+
///
69+
/// Not automatically closed if created externally and passed as an argument
70+
/// during construction.
6771
final Dio _dioClient;
6872

73+
/// Whether [_dioClient] was created on construction (and not passed in)
74+
final bool _isInternallyCreatedClient;
75+
6976
/// Each [Completer] is completed once the corresponding tile has finished
7077
/// loading
7178
///
@@ -103,7 +110,7 @@ base class CancellableNetworkTileProvider extends TileProvider {
103110
if (_tilesInProgress.isNotEmpty) {
104111
await Future.wait(_tilesInProgress.values.map((c) => c.future));
105112
}
106-
_dioClient.close();
113+
if (_isInternallyCreatedClient) _dioClient.close();
107114
super.dispose();
108115
}
109116
}

0 commit comments

Comments
 (0)