From cc41e25f21b5afcb87c256cd9a6813a23c953008 Mon Sep 17 00:00:00 2001 From: Kostia Sokolovskyi Date: Wed, 11 Oct 2023 17:45:39 +0200 Subject: [PATCH] _RenderSnapshotWidget should dispose created OffsetLayer. (#136267) --- .../flutter/lib/src/widgets/snapshot_widget.dart | 1 + .../test/widgets/snapshot_widget_test.dart | 16 +++------------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/packages/flutter/lib/src/widgets/snapshot_widget.dart b/packages/flutter/lib/src/widgets/snapshot_widget.dart index 854512f1f4..c680d58533 100644 --- a/packages/flutter/lib/src/widgets/snapshot_widget.dart +++ b/packages/flutter/lib/src/widgets/snapshot_widget.dart @@ -306,6 +306,7 @@ class _RenderSnapshotWidget extends RenderProxyBox { // ignore: invalid_use_of_protected_member context.stopRecordingIfNeeded(); if (mode != SnapshotMode.forced && !offsetLayer.supportsRasterization()) { + offsetLayer.dispose(); if (mode == SnapshotMode.normal) { throw FlutterError('SnapshotWidget used with a child that contains a PlatformView.'); } diff --git a/packages/flutter/test/widgets/snapshot_widget_test.dart b/packages/flutter/test/widgets/snapshot_widget_test.dart index e6faaa97a0..7bc8cd7761 100644 --- a/packages/flutter/test/widgets/snapshot_widget_test.dart +++ b/packages/flutter/test/widgets/snapshot_widget_test.dart @@ -217,7 +217,7 @@ void main() { }, skip: kIsWeb); // TODO(jonahwilliams): https://github.com/flutter/flutter/issues/106689 - testWidgets('RenderSnapshotWidget throws assertion if platform view is encountered', (WidgetTester tester) async { + testWidgetsWithLeakTracking('RenderSnapshotWidget throws assertion if platform view is encountered', (WidgetTester tester) async { final SnapshotController controller = SnapshotController(allowSnapshotting: true); addTearDown(controller.dispose); @@ -286,12 +286,7 @@ void main() { expect(tester.takeException(), isNull); expect(tester.layers.last, isA()); }, - skip: kIsWeb, // TODO(jonahwilliams): https://github.com/flutter/flutter/issues/106689 - leakTrackingTestConfig: const LeakTrackingTestConfig( - // TODO(ksokolovskyi): remove after fixing - // https://github.com/flutter/flutter/issues/135141 - allowAllNotDisposed: true, - )); + skip: kIsWeb); // TODO(jonahwilliams): https://github.com/flutter/flutter/issues/106689 testWidgetsWithLeakTracking('SnapshotWidget should have same result when enabled', (WidgetTester tester) async { addTearDown(tester.view.reset); @@ -330,12 +325,7 @@ void main() { await expectLater(find.byKey(repaintBoundaryKey), matchesReferenceImage(imageWhenDisabled)); }, - skip: kIsWeb, // TODO(jonahwilliams): https://github.com/flutter/flutter/issues/106689 - leakTrackingTestConfig: const LeakTrackingTestConfig( - // TODO(ksokolovskyi): remove after fixing - // https://github.com/flutter/flutter/issues/135137 - notDisposedAllowList: {'Image': 1}, - )); + skip: kIsWeb); // TODO(jonahwilliams): https://github.com/flutter/flutter/issues/106689 } class TestPlatformView extends SingleChildRenderObjectWidget {