From 98de8eb153e944e4fd83d5b93f5ee7273e7a77d3 Mon Sep 17 00:00:00 2001 From: Pascal Welsch Date: Mon, 18 Sep 2023 17:32:51 +0200 Subject: [PATCH] Be backwards compatible with Flutter 3.13 --- lib/src/utils/changenotifier2.dart | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/src/utils/changenotifier2.dart b/lib/src/utils/changenotifier2.dart index 03b189d0..660d7932 100644 --- a/lib/src/utils/changenotifier2.dart +++ b/lib/src/utils/changenotifier2.dart @@ -21,7 +21,7 @@ class ChangeNotifier2 implements ChangeNotifier { final List listeners = []; ChangeNotifier2() { - if (kFlutterMemoryAllocationsEnabled) { + if (_kFlutterMemoryAllocationsEnabled) { maybeDispatchObjectCreation(); } } @@ -32,7 +32,7 @@ class ChangeNotifier2 implements ChangeNotifier { throw "$instanceName is already disposed."; } - if (kFlutterMemoryAllocationsEnabled) { + if (_kFlutterMemoryAllocationsEnabled) { maybeDispatchObjectCreation(); } listeners.add(listener); @@ -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', @@ -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;