SnapshotPainter should dispatch creation and disposal events. (#138810)

This commit is contained in:
Kostia Sokolovskyi
2023-12-07 22:24:15 +01:00
committed by GitHub
parent 3c422dd750
commit 6c29986b28
2 changed files with 19 additions and 1 deletions

View File

@@ -4,6 +4,7 @@
import 'dart:ui' as ui;
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'basic.dart';
@@ -385,7 +386,14 @@ class _RenderSnapshotWidget extends RenderProxyBox {
/// }
/// ```
/// {@end-tool}
abstract class SnapshotPainter extends ChangeNotifier {
abstract class SnapshotPainter extends ChangeNotifier {
/// Creates an instance of [SnapshotPainter].
SnapshotPainter() {
if (kFlutterMemoryAllocationsEnabled) {
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}
/// Called whenever the [image] that represents a [SnapshotWidget]s child should be painted.
///
/// The image is rasterized at the physical pixel resolution and should be scaled down by

View File

@@ -326,6 +326,16 @@ void main() {
await expectLater(find.byKey(repaintBoundaryKey), matchesReferenceImage(imageWhenDisabled));
},
skip: kIsWeb); // TODO(jonahwilliams): https://github.com/flutter/flutter/issues/106689
test('SnapshotPainter dispatches memory events', () async {
await expectLater(
await memoryEvents(
() => TestPainter().dispose(),
TestPainter,
),
areCreateAndDispose,
);
});
}
class TestPlatformView extends SingleChildRenderObjectWidget {