Unverified Commit 60fae58a authored by Polina Cherkasova's avatar Polina Cherkasova Committed by GitHub

Add disposal mechanism for created Layers to TestRecordingPaintingContext. (#134768)

Contributes to https://github.com/flutter/flutter/issues/134575
parent c66ca4f1
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
/// An [Invocation] and the [stack] trace that led to it.
......@@ -96,6 +97,8 @@ class TestRecordingPaintingContext extends ClipContext implements PaintingContex
/// Creates a [PaintingContext] for tests that use [TestRecordingCanvas].
TestRecordingPaintingContext(this.canvas);
final List<OpacityLayer> _createdLayers = <OpacityLayer>[];
@override
final Canvas canvas;
......@@ -170,7 +173,18 @@ class TestRecordingPaintingContext extends ClipContext implements PaintingContex
canvas.saveLayer(null, Paint()); // TODO(ianh): Expose the alpha somewhere.
painter(this, offset);
canvas.restore();
return OpacityLayer();
final OpacityLayer layer = OpacityLayer();
_createdLayers.add(layer);
return layer;
}
/// Releases allocated resources.
@mustCallSuper
void dispose() {
for (final OpacityLayer layer in _createdLayers) {
layer.dispose();
}
_createdLayers.clear();
}
@override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment