Skip to content

Commit 6591934

Browse files
authored
Handle deprecation in Flutter. (#203)
1 parent 3d4c0d6 commit 6591934

File tree

7 files changed

+19
-11
lines changed

7 files changed

+19
-11
lines changed

examples/leak_tracking/lib/main.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import 'package:leak_tracker/leak_tracker.dart';
44

55
void main() {
66
LeakTracking.start();
7-
MemoryAllocations.instance.addListener(
7+
// Dispatch memory events from the Flutter engine to LeakTracking.
8+
FlutterMemoryAllocations.instance.addListener(
89
(ObjectEvent event) => LeakTracking.dispatchObjectEvent(event.toMap()),
910
);
1011

pkgs/leak_tracker_flutter_testing/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.2
2+
3+
* Replaced depracated `MemoryAllocations` with `FlutterMemoryAllocations`.
4+
15
## 2.0.1
26

37
* Upgrade to leak_tracker 10.0.0 and leak_tracker_testing 2.0.1.

pkgs/leak_tracker_flutter_testing/lib/src/matchers.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:flutter/foundation.dart';
88
import 'package:matcher/matcher.dart';
99

1010
/// Invokes [callback] and collects
11-
/// events dispatched to [MemoryAllocations.instance] for [type].
11+
/// events dispatched to [FlutterMemoryAllocations.instance] for [type].
1212
Future<List<ObjectEvent>> memoryEvents(
1313
FutureOr<void> Function() callback,
1414
Type type,
@@ -21,9 +21,9 @@ Future<List<ObjectEvent>> memoryEvents(
2121
}
2222
}
2323

24-
MemoryAllocations.instance.addListener(listener);
24+
FlutterMemoryAllocations.instance.addListener(listener);
2525
await callback();
26-
MemoryAllocations.instance.removeListener(listener);
26+
FlutterMemoryAllocations.instance.removeListener(listener);
2727

2828
return events;
2929
}

pkgs/leak_tracker_flutter_testing/lib/src/testing.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ Future<void> maybeTearDownLeakTrackingForAll() async {
6060

6161
// The listener is not added/removed for each test,
6262
// because GC may happen after test is complete.
63-
MemoryAllocations.instance.removeListener(_dispatchFlutterEventToLeakTracker);
63+
FlutterMemoryAllocations.instance
64+
.removeListener(_dispatchFlutterEventToLeakTracker);
6465
await forceGC(fullGcCycles: defaultNumberOfGcCycles);
6566
LeakTracking.declareNotDisposedObjectsAsLeaks();
6667
final leaks = await LeakTracking.collectLeaks();
@@ -107,5 +108,6 @@ void _maybeStartLeakTracking() {
107108

108109
LeakTracking.phase = const PhaseSettings.ignored();
109110
LeakTracking.start(config: LeakTrackingConfig.passive());
110-
MemoryAllocations.instance.addListener(_dispatchFlutterEventToLeakTracker);
111+
FlutterMemoryAllocations.instance
112+
.addListener(_dispatchFlutterEventToLeakTracker);
111113
}

pkgs/leak_tracker_flutter_testing/pubspec.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name: leak_tracker_flutter_testing
2-
version: 2.0.1
2+
version: 2.0.2
33
description: An internal package to test leak tracking with Flutter.
44
repository: https://github.com/dart-lang/leak_tracker/tree/main/pkgs/leak_tracker_flutter_testing
55

66
environment:
7-
sdk: '>=3.1.2 <4.0.0'
7+
sdk: '>=3.2.0 <4.0.0'
8+
flutter: '>=3.18.0-18.0.pre.54'
89

910
dependencies:
1011
flutter:

pkgs/leak_tracker_flutter_testing/test/tests/_dispatcher_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void main() {
1414
test('dispatchObjectEvent dispatches Flutter SDK instrumentation.', () {
1515
final tracker = EventTracker();
1616

17-
MemoryAllocations.instance.addListener(
17+
FlutterMemoryAllocations.instance.addListener(
1818
(event) => dispatchObjectEvent(
1919
event.toMap(),
2020
onStartTracking: tracker.dispatchObjectCreated,

pkgs/leak_tracker_flutter_testing/test/tests/matchers_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import 'package:test/test.dart';
88

99
class _TrackedClass {
1010
_TrackedClass() {
11-
MemoryAllocations.instance.dispatchObjectCreated(
11+
FlutterMemoryAllocations.instance.dispatchObjectCreated(
1212
library: 'library',
1313
className: '_TrackedClass',
1414
object: this,
1515
);
1616
}
1717

1818
void dispose() {
19-
MemoryAllocations.instance.dispatchObjectDisposed(object: this);
19+
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
2020
}
2121
}
2222

0 commit comments

Comments
 (0)