Skip to content

Commit

Permalink
Add disposal mechanism for created Layers to TestRecordingPaintingCon…
Browse files Browse the repository at this point in the history
…text. (#134768)

Contributes to flutter/flutter#134575
  • Loading branch information
polina-c authored Sep 16, 2023
1 parent c66ca4f commit 60fae58
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/flutter_test/lib/src/recording_canvas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 60fae58

Please sign in to comment.