InkFeature should dispatch creation and disposal events. (#137793)
This commit is contained in:
parent
2369897f09
commit
a52f030cda
@ -709,7 +709,17 @@ abstract class InkFeature {
|
|||||||
required MaterialInkController controller,
|
required MaterialInkController controller,
|
||||||
required this.referenceBox,
|
required this.referenceBox,
|
||||||
this.onRemoved,
|
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].
|
/// The [MaterialInkController] associated with this [InkFeature].
|
||||||
///
|
///
|
||||||
@ -734,6 +744,11 @@ abstract class InkFeature {
|
|||||||
_debugDisposed = true;
|
_debugDisposed = true;
|
||||||
return 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);
|
_controller._removeFeature(this);
|
||||||
onRemoved?.call();
|
onRemoved?.call();
|
||||||
}
|
}
|
||||||
|
@ -1120,6 +1120,31 @@ void main() {
|
|||||||
// Force a repaint again. This time, it gets repainted because it is onstage.
|
// Force a repaint again. This time, it gets repainted because it is onstage.
|
||||||
materialKey.currentContext!.findRenderObject()!.paint(PaintingContext(layer2, Rect.largest), Offset.zero);
|
materialKey.currentContext!.findRenderObject()!.paint(PaintingContext(layer2, Rect.largest), Offset.zero);
|
||||||
expect(tracker.paintCount, 2);
|
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', () {
|
group('LookupBoundary', () {
|
||||||
@ -1227,3 +1252,15 @@ class TrackPaintInkFeature extends InkFeature {
|
|||||||
paintCount += 1;
|
paintCount += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _InkFeature extends InkFeature {
|
||||||
|
_InkFeature({
|
||||||
|
required super.controller,
|
||||||
|
required super.referenceBox,
|
||||||
|
}) {
|
||||||
|
controller.addInkFeature(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void paintFeature(Canvas canvas, Matrix4 transform) {}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user