From 1b4a5c93b91368e61d39f3558b2a308d9e0c9acf Mon Sep 17 00:00:00 2001 From: JaffaKetchup Date: Sun, 10 Sep 2023 10:22:00 +0100 Subject: [PATCH] Reflect changes in fleaflet/flutter_map#1648 --- ...flutter_map_cancellable_tile_provider.dart | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/flutter_map_cancellable_tile_provider.dart b/lib/flutter_map_cancellable_tile_provider.dart index cb44dbb..fe9ec85 100644 --- a/lib/flutter_map_cancellable_tile_provider.dart +++ b/lib/flutter_map_cancellable_tile_provider.dart @@ -121,17 +121,23 @@ class _CNTPImageProvider extends ImageProvider<_CNTPImageProvider> { final cancelToken = CancelToken(); unawaited(cancelLoading.then((_) => cancelToken.cancel())); - final Uint8List bytes; try { - final response = await tileProvider._dio.get( - useFallback ? fallbackUrl! : url, - cancelToken: cancelToken, - options: Options( - headers: tileProvider.headers, - responseType: ResponseType.bytes, + final codec = decode( + await ImmutableBuffer.fromUint8List( + (await tileProvider._dio.get( + useFallback ? fallbackUrl! : url, + cancelToken: cancelToken, + options: Options( + headers: tileProvider.headers, + responseType: ResponseType.bytes, + ), + )) + .data!, ), ); - bytes = response.data!; + + cancelLoading.ignore(); + return codec; } on DioException catch (err) { if (CancelToken.isCancel(err)) { return decode( @@ -146,9 +152,6 @@ class _CNTPImageProvider extends ImageProvider<_CNTPImageProvider> { if (useFallback || fallbackUrl == null) rethrow; return _loadAsync(key, chunkEvents, decode, useFallback: true); } - - cancelLoading.ignore(); - return decode(await ImmutableBuffer.fromUint8List(bytes)); } @override