Unverified Commit 4880aab1 authored by Kostia Sokolovskyi's avatar Kostia Sokolovskyi Committed by GitHub

ScrollActivity should dispatch creation and disposal events. (#137961)

parent 2d9a075d
......@@ -57,7 +57,17 @@ abstract class ScrollActivityDelegate {
/// [ScrollPosition] of a [Scrollable].
abstract class ScrollActivity {
/// Initializes [delegate] for subclasses.
ScrollActivity(this._delegate);
ScrollActivity(this._delegate) {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
MemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/widgets.dart',
className: '$ScrollActivity',
object: this,
);
}
}
/// The delegate that this activity will use to actuate the scroll view.
ScrollActivityDelegate get delegate => _delegate;
......@@ -137,6 +147,12 @@ abstract class ScrollActivity {
/// Called when the scroll view stops performing this activity.
@mustCallSuper
void dispose() {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
MemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
_isDisposed = true;
}
......
......@@ -212,6 +212,16 @@ void main() {
expect(lastTapped, equals(3));
await tester.pumpAndSettle();
});
test('$ScrollActivity dispatches memory events', () async {
await expectLater(
await memoryEvents(
() => _ScrollActivity(_ScrollActivityDelegate()).dispose(),
_ScrollActivity,
),
areCreateAndDispose,
);
});
}
class PageView62209 extends StatefulWidget {
......@@ -359,3 +369,33 @@ class _Carousel62209State extends State<Carousel62209> {
);
}
}
class _ScrollActivity extends ScrollActivity {
_ScrollActivity(super.delegate);
@override
bool get isScrolling => false;
@override
bool get shouldIgnorePointer => true;
@override
double get velocity => 0.0;
}
class _ScrollActivityDelegate extends ScrollActivityDelegate {
@override
void applyUserOffset(double delta) {}
@override
AxisDirection get axisDirection => AxisDirection.down;
@override
void goBallistic(double velocity) {}
@override
void goIdle() {}
@override
double setPixels(double pixels) => 0.0;
}
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