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

Contributes to https://github.com/flutter/flutter/issues/134575
This commit is contained in:
Polina Cherkasova 2023-09-16 12:50:23 -07:00 committed by GitHub
parent c66ca4f14b
commit 60fae58a24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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