Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle deprecation in Flutter. #203

Merged
merged 5 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/leak_tracking/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import 'package:leak_tracker/leak_tracker.dart';

void main() {
LeakTracking.start();
MemoryAllocations.instance.addListener(
// Dispatch memory events from the Flutter engine to LeakTracking.
FlutterMemoryAllocations.instance.addListener(
polina-c marked this conversation as resolved.
Show resolved Hide resolved
(ObjectEvent event) => LeakTracking.dispatchObjectEvent(event.toMap()),
);

Expand Down
4 changes: 4 additions & 0 deletions pkgs/leak_tracker_flutter_testing/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.2

* Replaced depracated `MemoryAllocations` with `FlutterMemoryAllocations`.

## 2.0.1

* Upgrade to leak_tracker 10.0.0 and leak_tracker_testing 2.0.1.
Expand Down
6 changes: 3 additions & 3 deletions pkgs/leak_tracker_flutter_testing/lib/src/matchers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:flutter/foundation.dart';
import 'package:matcher/matcher.dart';

/// Invokes [callback] and collects
/// events dispatched to [MemoryAllocations.instance] for [type].
/// events dispatched to [FlutterMemoryAllocations.instance] for [type].
Future<List<ObjectEvent>> memoryEvents(
FutureOr<void> Function() callback,
Type type,
Expand All @@ -21,9 +21,9 @@ Future<List<ObjectEvent>> memoryEvents(
}
}

MemoryAllocations.instance.addListener(listener);
FlutterMemoryAllocations.instance.addListener(listener);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When was FlutterMemoryAllocations added to package:flutter? Do we need to update the min. sdk constraint for this package (in order to specify a min. sdk that contains this typedef)?

await callback();
MemoryAllocations.instance.removeListener(listener);
FlutterMemoryAllocations.instance.removeListener(listener);

return events;
}
Expand Down
6 changes: 4 additions & 2 deletions pkgs/leak_tracker_flutter_testing/lib/src/testing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ Future<void> maybeTearDownLeakTrackingForAll() async {

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

LeakTracking.phase = const PhaseSettings.ignored();
LeakTracking.start(config: LeakTrackingConfig.passive());
MemoryAllocations.instance.addListener(_dispatchFlutterEventToLeakTracker);
FlutterMemoryAllocations.instance
.addListener(_dispatchFlutterEventToLeakTracker);
}
5 changes: 3 additions & 2 deletions pkgs/leak_tracker_flutter_testing/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: leak_tracker_flutter_testing
version: 2.0.1
version: 2.0.2
description: An internal package to test leak tracking with Flutter.
repository: https://github.com/dart-lang/leak_tracker/tree/main/pkgs/leak_tracker_flutter_testing

environment:
sdk: '>=3.1.2 <4.0.0'
sdk: '>=3.2.0 <4.0.0'
flutter: '>=3.18.0-18.0.pre.54'

dependencies:
flutter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void main() {
test('dispatchObjectEvent dispatches Flutter SDK instrumentation.', () {
final tracker = EventTracker();

MemoryAllocations.instance.addListener(
FlutterMemoryAllocations.instance.addListener(
(event) => dispatchObjectEvent(
event.toMap(),
onStartTracking: tracker.dispatchObjectCreated,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import 'package:test/test.dart';

class _TrackedClass {
_TrackedClass() {
MemoryAllocations.instance.dispatchObjectCreated(
FlutterMemoryAllocations.instance.dispatchObjectCreated(
library: 'library',
className: '_TrackedClass',
object: this,
);
}

void dispose() {
MemoryAllocations.instance.dispatchObjectDisposed(object: this);
FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
}

Expand Down