Skip to content

Commit 6d4d012

Browse files
authored
ScrollDragController should dispatch creation and disposal events. (#138800)
1 parent 6784135 commit 6d4d012

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎packages/flutter/lib/src/widgets/scroll_activity.dart‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,17 @@ class ScrollDragController implements Drag {
261261
_retainMomentum = carriedVelocity != null && carriedVelocity != 0.0,
262262
_lastNonStationaryTimestamp = details.sourceTimeStamp,
263263
_kind = details.kind,
264-
_offsetSinceLastStop = motionStartDistanceThreshold == null ? null : 0.0;
264+
_offsetSinceLastStop = motionStartDistanceThreshold == null ? null : 0.0 {
265+
// TODO(polina-c): stop duplicating code across disposables
266+
// https://github.com/flutter/flutter/issues/137435
267+
if (kFlutterMemoryAllocationsEnabled) {
268+
MemoryAllocations.instance.dispatchObjectCreated(
269+
library: 'package:flutter/widgets.dart',
270+
className: '$ScrollDragController',
271+
object: this,
272+
);
273+
}
274+
}
265275

266276
/// The object that will actuate the scroll view as the user drags.
267277
ScrollActivityDelegate get delegate => _delegate;
@@ -437,6 +447,11 @@ class ScrollDragController implements Drag {
437447
/// Called by the delegate when it is no longer sending events to this object.
438448
@mustCallSuper
439449
void dispose() {
450+
// TODO(polina-c): stop duplicating code across disposables
451+
// https://github.com/flutter/flutter/issues/137435
452+
if (kFlutterMemoryAllocationsEnabled) {
453+
MemoryAllocations.instance.dispatchObjectDisposed(object: this);
454+
}
440455
_lastDetails = null;
441456
onDragCanceled?.call();
442457
}

‎packages/flutter/test/widgets/scroll_activity_test.dart‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,19 @@ void main() {
222222
areCreateAndDispose,
223223
);
224224
});
225+
226+
test('$ScrollDragController dispatches memory events', () async {
227+
await expectLater(
228+
await memoryEvents(
229+
() => ScrollDragController(
230+
delegate: _ScrollActivityDelegate(),
231+
details: DragStartDetails(),
232+
).dispose(),
233+
ScrollDragController,
234+
),
235+
areCreateAndDispose,
236+
);
237+
});
225238
}
226239

227240
class PageView62209 extends StatefulWidget {

0 commit comments

Comments
 (0)