From 817f6013c3a8bae5738637dcb51a8db90bcfe946 Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Fri, 13 Dec 2024 21:47:00 +0800 Subject: [PATCH 1/3] fix: Fix memory leaks --- packages/camera/camera/example/lib/main.dart | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/camera/camera/example/lib/main.dart b/packages/camera/camera/example/lib/main.dart index d048fc794f28..cda92aadfd34 100644 --- a/packages/camera/camera/example/lib/main.dart +++ b/packages/camera/camera/example/lib/main.dart @@ -54,12 +54,12 @@ class _CameraExampleHomeState extends State double _minAvailableExposureOffset = 0.0; double _maxAvailableExposureOffset = 0.0; double _currentExposureOffset = 0.0; - late AnimationController _flashModeControlRowAnimationController; - late Animation _flashModeControlRowAnimation; - late AnimationController _exposureModeControlRowAnimationController; - late Animation _exposureModeControlRowAnimation; - late AnimationController _focusModeControlRowAnimationController; - late Animation _focusModeControlRowAnimation; + late final AnimationController _flashModeControlRowAnimationController; + late final CurvedAnimation _flashModeControlRowAnimation; + late final AnimationController _exposureModeControlRowAnimationController; + late final CurvedAnimation _exposureModeControlRowAnimation; + late final AnimationController _focusModeControlRowAnimationController; + late final CurvedAnimation _focusModeControlRowAnimation; double _minAvailableZoom = 1.0; double _maxAvailableZoom = 1.0; double _currentScale = 1.0; @@ -103,7 +103,11 @@ class _CameraExampleHomeState extends State void dispose() { WidgetsBinding.instance.removeObserver(this); _flashModeControlRowAnimationController.dispose(); + _flashModeControlRowAnimation.dispose(); _exposureModeControlRowAnimationController.dispose(); + _exposureModeControlRowAnimation.dispose(); + _focusModeControlRowAnimationController.dispose(); + _focusModeControlRowAnimation.dispose(); super.dispose(); } From eebb64f3094adc7ee3712cbea1f23ea8005a7a8a Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Fri, 13 Dec 2024 21:47:08 +0800 Subject: [PATCH 2/3] test: Activate memory leak --- packages/camera/camera/example/pubspec.yaml | 1 + .../camera/example/test/flutter_test_config.dart | 13 +++++++++++++ packages/camera/camera/pubspec.yaml | 1 + .../camera/camera/test/camera_preview_test.dart | 4 ++++ .../camera/camera/test/flutter_test_config.dart | 13 +++++++++++++ 5 files changed, 32 insertions(+) create mode 100644 packages/camera/camera/example/test/flutter_test_config.dart create mode 100644 packages/camera/camera/test/flutter_test_config.dart diff --git a/packages/camera/camera/example/pubspec.yaml b/packages/camera/camera/example/pubspec.yaml index b1627987aed2..aff0afef21fe 100644 --- a/packages/camera/camera/example/pubspec.yaml +++ b/packages/camera/camera/example/pubspec.yaml @@ -27,6 +27,7 @@ dev_dependencies: sdk: flutter integration_test: sdk: flutter + leak_tracker_flutter_testing: any flutter: uses-material-design: true diff --git a/packages/camera/camera/example/test/flutter_test_config.dart b/packages/camera/camera/example/test/flutter_test_config.dart new file mode 100644 index 000000000000..9907e578b84b --- /dev/null +++ b/packages/camera/camera/example/test/flutter_test_config.dart @@ -0,0 +1,13 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; + +Future testExecutable(FutureOr Function() testMain) async { + LeakTesting.enable(); + LeakTracking.warnForUnsupportedPlatforms = false; + await testMain(); +} diff --git a/packages/camera/camera/pubspec.yaml b/packages/camera/camera/pubspec.yaml index fb4e49510968..d8144150bccd 100644 --- a/packages/camera/camera/pubspec.yaml +++ b/packages/camera/camera/pubspec.yaml @@ -32,6 +32,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter + leak_tracker_flutter_testing: any mockito: ^5.4.4 plugin_platform_interface: ^2.1.7 diff --git a/packages/camera/camera/test/camera_preview_test.dart b/packages/camera/camera/test/camera_preview_test.dart index 4b5a2a5b5163..d76ac7ea02ec 100644 --- a/packages/camera/camera/test/camera_preview_test.dart +++ b/packages/camera/camera/test/camera_preview_test.dart @@ -144,6 +144,7 @@ void main() { debugDefaultTargetPlatformOverride = TargetPlatform.android; final FakeController controller = FakeController(); + addTearDown(controller.dispose); controller.value = controller.value.copyWith( isInitialized: true, isRecordingVideo: true, @@ -179,6 +180,7 @@ void main() { debugDefaultTargetPlatformOverride = TargetPlatform.android; final FakeController controller = FakeController(); + addTearDown(controller.dispose); controller.value = controller.value.copyWith( isInitialized: true, deviceOrientation: DeviceOrientation.portraitUp, @@ -213,6 +215,7 @@ void main() { debugDefaultTargetPlatformOverride = TargetPlatform.android; final FakeController controller = FakeController(); + addTearDown(controller.dispose); controller.value = controller.value.copyWith( isInitialized: true, deviceOrientation: DeviceOrientation.portraitUp, @@ -241,6 +244,7 @@ void main() { (WidgetTester tester) async { debugDefaultTargetPlatformOverride = TargetPlatform.iOS; final FakeController controller = FakeController(); + addTearDown(controller.dispose); controller.value = controller.value.copyWith( isInitialized: true, previewSize: const Size(480, 640), diff --git a/packages/camera/camera/test/flutter_test_config.dart b/packages/camera/camera/test/flutter_test_config.dart new file mode 100644 index 000000000000..9907e578b84b --- /dev/null +++ b/packages/camera/camera/test/flutter_test_config.dart @@ -0,0 +1,13 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; + +Future testExecutable(FutureOr Function() testMain) async { + LeakTesting.enable(); + LeakTracking.warnForUnsupportedPlatforms = false; + await testMain(); +} From b58402aed7c05a99f4ae54770e502ed027eacbf7 Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Fri, 27 Dec 2024 20:03:49 +0800 Subject: [PATCH 3/3] doc: Update changelog --- packages/camera/camera/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/camera/camera/CHANGELOG.md b/packages/camera/camera/CHANGELOG.md index f0de02ef0cd8..5e923b81d2c5 100644 --- a/packages/camera/camera/CHANGELOG.md +++ b/packages/camera/camera/CHANGELOG.md @@ -1,6 +1,7 @@ ## NEXT * Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. +* Updates example to dispose animation controllers and curved animations. ## 0.11.0+2