Skip to content

Commit

Permalink
InkFeature should dispatch creation and disposal events. (#137793)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksokolovskyi authored Nov 3, 2023
1 parent 2369897 commit a52f030
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/flutter/lib/src/material/material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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].
///
Expand All @@ -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();
}
Expand Down
37 changes: 37 additions & 0 deletions packages/flutter/test/material/material_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down Expand Up @@ -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) {}
}

0 comments on commit a52f030

Please sign in to comment.