Skip to content

Commit

Permalink
Be backwards compatible with Flutter 3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
passsy committed Oct 12, 2023
1 parent 7f3de2e commit 98de8eb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/src/utils/changenotifier2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ChangeNotifier2 implements ChangeNotifier {
final List<void Function()> listeners = [];

ChangeNotifier2() {
if (kFlutterMemoryAllocationsEnabled) {
if (_kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
}
}
Expand All @@ -32,7 +32,7 @@ class ChangeNotifier2 implements ChangeNotifier {
throw "$instanceName is already disposed.";
}

if (kFlutterMemoryAllocationsEnabled) {
if (_kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
}
listeners.add(listener);
Expand Down Expand Up @@ -79,10 +79,11 @@ class ChangeNotifier2 implements ChangeNotifier {
}

@override
// ignore: override_on_non_overriding_member
void maybeDispatchObjectCreation() {
// Tree shaker does not include this method and the class MemoryAllocations
// if kFlutterMemoryAllocationsEnabled is false.
if (kFlutterMemoryAllocationsEnabled && !_creationDispatched) {
if (_kFlutterMemoryAllocationsEnabled && !_creationDispatched) {
MemoryAllocations.instance.dispatchObjectCreated(
library: 'package:wiredash/src/utils/changenotifier2.dart',
className: '$ChangeNotifier2',
Expand All @@ -92,3 +93,11 @@ class ChangeNotifier2 implements ChangeNotifier {
}
}
}

const bool _kMemoryAllocations =
bool.fromEnvironment('flutter.memory_allocations');

/// Copy of [kFlutterMemoryAllocationsEnabled] to be backwards compatible with
/// Flutter 3.13 and earlier
const bool _kFlutterMemoryAllocationsEnabled =
_kMemoryAllocations || kDebugMode;

0 comments on commit 98de8eb

Please sign in to comment.