diff --git a/dev/tracing_tests/test/image_cache_tracing_test.dart b/dev/tracing_tests/test/image_cache_tracing_test.dart index dde8c8373d..3d8a9b3b18 100644 --- a/dev/tracing_tests/test/image_cache_tracing_test.dart +++ b/dev/tracing_tests/test/image_cache_tracing_test.dart @@ -5,6 +5,8 @@ import 'dart:convert'; import 'dart:developer' as developer; import 'dart:isolate' as isolate; +import 'dart:typed_data'; +import 'dart:ui' as ui; import 'package:flutter/painting.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -31,12 +33,21 @@ void main() { test('Image cache tracing', () async { final TestImageStreamCompleter completer1 = TestImageStreamCompleter(); + final TestImageStreamCompleter completer2 = TestImageStreamCompleter(); PaintingBinding.instance.imageCache.putIfAbsent( 'Test', () => completer1, ); PaintingBinding.instance.imageCache.clear(); + // ignore: invalid_use_of_protected_member + completer2.setImage(const ImageInfo(image: TestImage())); + PaintingBinding.instance.imageCache.putIfAbsent( + 'Test2', + () => completer2, + ); + PaintingBinding.instance.imageCache.evict('Test2'); + final Timeline timeline = await vmService.getVMTimeline(); _expectTimelineEvents( timeline.traceEvents, @@ -59,6 +70,14 @@ void main() { 'isolateId': isolateId, } }, + { + 'name': 'ImageCache.putIfAbsent', + 'args': {'key': 'Test2', 'isolateId': isolateId} + }, + { + 'name': 'ImageCache.evict', + 'args': {'sizeInBytes': 0, 'isolateId': isolateId} + }, ], ); }, skip: isBrowser); // uses dart:isolate and io @@ -92,3 +111,19 @@ bool _mapsEqual(Map expectedArgs, Map args) { } class TestImageStreamCompleter extends ImageStreamCompleter {} + +class TestImage implements ui.Image { + const TestImage({this.height = 0, this.width = 0}); + @override + final int height; + @override + final int width; + + @override + void dispose() { } + + @override + Future toByteData({ ui.ImageByteFormat format = ui.ImageByteFormat.rawRgba }) { + throw UnimplementedError(); + } +} diff --git a/packages/flutter/lib/src/painting/image_cache.dart b/packages/flutter/lib/src/painting/image_cache.dart index dbdf7b0c82..777a888732 100644 --- a/packages/flutter/lib/src/painting/image_cache.dart +++ b/packages/flutter/lib/src/painting/image_cache.dart @@ -31,7 +31,7 @@ const int _kDefaultSizeBytes = 100 << 20; // 100 MiB /// /// A caller can determine whether an image is already in the cache by using /// [containsKey], which will return true if the image is tracked by the cache -/// in a pending or compelted state. More fine grained information is available +/// in a pending or completed state. More fine grained information is available /// by using the [statusForKey] method. /// /// Generally this class is not used directly. The [ImageProvider] class and its @@ -255,7 +255,7 @@ class ImageCache { if (!kReleaseMode) { Timeline.instantSync('ImageCache.evict', arguments: { 'type': 'keepAlive', - 'sizeiInBytes': image.sizeBytes, + 'sizeInBytes': image.sizeBytes, }); } _currentSizeBytes -= image.sizeBytes;