diff --git a/packages/flutter/lib/src/painting/_network_image_io.dart b/packages/flutter/lib/src/painting/_network_image_io.dart index b069afe26f..fb485ce2ea 100644 --- a/packages/flutter/lib/src/painting/_network_image_io.dart +++ b/packages/flutter/lib/src/painting/_network_image_io.dart @@ -96,6 +96,7 @@ class NetworkImage extends image_provider.ImageProvider>(); throw image_provider.NetworkImageLoadException(statusCode: response.statusCode, uri: resolved); } diff --git a/packages/flutter/test/painting/image_provider_network_image_test.dart b/packages/flutter/test/painting/image_provider_network_image_test.dart index efc333f2dd..8c3c64b660 100644 --- a/packages/flutter/test/painting/image_provider_network_image_test.dart +++ b/packages/flutter/test/painting/image_provider_network_image_test.dart @@ -35,7 +35,7 @@ void main() { PaintingBinding.instance!.imageCache!.clearLiveImages(); }); - test('Expect thrown exception with statusCode - evicts from cache', () async { + test('Expect thrown exception with statusCode - evicts from cache and drains', () async { final int errorStatusCode = HttpStatus.notFound; const String requestUrl = 'foo-url'; @@ -68,6 +68,7 @@ void main() { .having((NetworkImageLoadException e) => e.statusCode, 'statusCode', errorStatusCode) .having((NetworkImageLoadException e) => e.uri, 'uri', Uri.base.resolve(requestUrl)), ); + expect(httpClient.request.response.drained, true); }, skip: isBrowser); // Browser implementation does not use HTTP client but an tag. test('Uses the HttpClient provided by debugNetworkImageHttpClientProvider if set', () async { @@ -234,6 +235,8 @@ class _FakeHttpClientRequest extends Fake implements HttpClientRequest { } class _FakeHttpClientResponse extends Fake implements HttpClientResponse { + bool drained = false; + @override int statusCode = HttpStatus.ok; @@ -254,6 +257,12 @@ class _FakeHttpClientResponse extends Fake implements HttpClientResponse { cancelOnError: cancelOnError, ); } + + @override + Future drain([E? futureValue]) async { + drained = true; + return futureValue ?? [] as E; + } } class FakeCodec implements Codec {