mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Ticker should dispatch creation and disposal events. (#137844)
This commit is contained in:
parent
89692884a1
commit
ca384b84e5
@ -71,6 +71,15 @@ class Ticker {
|
||||
_debugCreationStack = StackTrace.current;
|
||||
return true;
|
||||
}());
|
||||
// TODO(polina-c): stop duplicating code across disposables
|
||||
// https://github.com/flutter/flutter/issues/137435
|
||||
if (kFlutterMemoryAllocationsEnabled) {
|
||||
MemoryAllocations.instance.dispatchObjectCreated(
|
||||
library: 'package:flutter/scheduler.dart',
|
||||
className: '$Ticker',
|
||||
object: this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
TickerFuture? _future;
|
||||
@ -319,6 +328,12 @@ class Ticker {
|
||||
/// with a [TickerCanceled] error.
|
||||
@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);
|
||||
}
|
||||
|
||||
if (_future != null) {
|
||||
final TickerFuture localFuture = _future!;
|
||||
_future = null;
|
||||
|
||||
@ -23,6 +23,7 @@ void main() {
|
||||
}
|
||||
|
||||
final Ticker ticker = Ticker(handleTick);
|
||||
addTearDown(ticker.dispose);
|
||||
|
||||
expect(ticker.isTicking, isFalse);
|
||||
expect(ticker.isActive, isFalse);
|
||||
@ -100,6 +101,7 @@ void main() {
|
||||
|
||||
testWidgetsWithLeakTracking('Ticker control test', (WidgetTester tester) async {
|
||||
late Ticker ticker;
|
||||
addTearDown(() => ticker.dispose());
|
||||
|
||||
void testFunction() {
|
||||
ticker = Ticker((Duration _) { });
|
||||
@ -154,6 +156,7 @@ void main() {
|
||||
}
|
||||
|
||||
final Ticker ticker = Ticker(handleTick);
|
||||
addTearDown(ticker.dispose);
|
||||
ticker.start();
|
||||
|
||||
expect(ticker.isTicking, isTrue);
|
||||
@ -179,6 +182,7 @@ void main() {
|
||||
}
|
||||
|
||||
final Ticker ticker = Ticker(handleTick);
|
||||
addTearDown(ticker.dispose);
|
||||
ticker.start();
|
||||
|
||||
expect(tickCount, equals(0));
|
||||
@ -198,4 +202,11 @@ void main() {
|
||||
|
||||
ticker.stop();
|
||||
});
|
||||
|
||||
test('Ticker dispatches memory events', () async {
|
||||
await expectLater(
|
||||
await memoryEvents(() => Ticker((_) {}).dispose(), Ticker,),
|
||||
areCreateAndDispose,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user