Unverified Commit a52f030c authored by Kostia Sokolovskyi's avatar Kostia Sokolovskyi Committed by GitHub

InkFeature should dispatch creation and disposal events. (#137793)

parent 2369897f
......@@ -709,7 +709,17 @@ abstract class InkFeature {
required MaterialInkController controller,
required this.referenceBox,
this.onRemoved,
}) : _controller = controller as _RenderInkFeatures;
}) : _controller = controller as _RenderInkFeatures {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
MemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/material.dart',
className: '$InkFeature',
object: this,
);
}
}
/// The [MaterialInkController] associated with this [InkFeature].
///
......@@ -734,6 +744,11 @@ abstract class InkFeature {
_debugDisposed = true;
return true;
}());
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
MemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
_controller._removeFeature(this);
onRemoved?.call();
}
......
......@@ -1120,6 +1120,31 @@ void main() {
// Force a repaint again. This time, it gets repainted because it is onstage.
materialKey.currentContext!.findRenderObject()!.paint(PaintingContext(layer2, Rect.largest), Offset.zero);
expect(tracker.paintCount, 2);
tracker.dispose();
});
testWidgetsWithLeakTracking('$InkFeature dispatches memory events', (WidgetTester tester) async {
await tester.pumpWidget(
const Material(
child: SizedBox(width: 20, height: 20),
),
);
final Element element = tester.element(find.byType(SizedBox));
final MaterialInkController controller = Material.of(element);
final RenderBox referenceBox = element.findRenderObject()! as RenderBox;
await expectLater(
await memoryEvents(
() => _InkFeature(
controller: controller,
referenceBox: referenceBox,
).dispose(),
_InkFeature,
),
areCreateAndDispose,
);
});
group('LookupBoundary', () {
......@@ -1227,3 +1252,15 @@ class TrackPaintInkFeature extends InkFeature {
paintCount += 1;
}
}
class _InkFeature extends InkFeature {
_InkFeature({
required super.controller,
required super.referenceBox,
}) {
controller.addInkFeature(this);
}
@override
void paintFeature(Canvas canvas, Matrix4 transform) {}
}
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