Skip to content

Commit abf2a89

Browse files
Sempakonkamvanbeusekom
authored and
Egor
committed
[Camera] Made CameraController.isDisposed publicly accessible. Added unit Tests for the new implementation. (flutter#3193)
* Update feedback from Flutter team * Removed obsolete dependency on mockito * Apply feedback on pull request * Bump version number * Update CHANGELOG description to reflect changes * Fix formatting * Refactor try..catch to returnsNormally * Fix formatting issues Co-authored-by: Maurits van Beusekom <[email protected]>
1 parent 81c1dae commit abf2a89

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

packages/camera/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.8+15
2+
3+
* Added the `debugCheckIsDisposed` method which can be used in debug mode to validate if the `CameraController` class has been disposed.
4+
15
## 0.5.8+14
26

37
* Changed the order of the setters for `mediaRecorder` in `MediaRecorderBuilder.java` to make it more readable.

packages/camera/lib/camera.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,13 @@ class CameraController extends ValueNotifier<CameraValue> {
307307
StreamSubscription<dynamic> _imageStreamSubscription;
308308
Completer<void> _creatingCompleter;
309309

310+
/// Checks whether [CameraController.dispose] has completed successfully.
311+
///
312+
/// This is a no-op when asserts are disabled.
313+
void debugCheckIsDisposed() {
314+
assert(_isDisposed);
315+
}
316+
310317
/// Initializes the camera on the device.
311318
///
312319
/// Throws a [CameraException] if the initialization fails.

packages/camera/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: camera
22
description: A Flutter plugin for getting information about and controlling the
33
camera on Android and iOS. Supports previewing the camera feed, capturing images, capturing video,
44
and streaming image buffers to dart.
5-
version: 0.5.8+14
5+
version: 0.5.8+15
66
homepage: https://github.com/flutter/plugins/tree/master/packages/camera
77

88
dependencies:

packages/camera/test/camera_test.dart

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
import 'package:camera/camera.dart';
5+
import 'package:flutter_test/flutter_test.dart';
6+
7+
void main() {
8+
group('camera', () {
9+
test('debugCheckIsDisposed should not throw assertion error when disposed',
10+
() {
11+
final MockCameraDescription description = MockCameraDescription();
12+
final CameraController controller = CameraController(
13+
description,
14+
ResolutionPreset.low,
15+
);
16+
17+
controller.dispose();
18+
19+
expect(controller.debugCheckIsDisposed, returnsNormally);
20+
});
21+
22+
test('debugCheckIsDisposed should throw assertion error when not disposed',
23+
() {
24+
final MockCameraDescription description = MockCameraDescription();
25+
final CameraController controller = CameraController(
26+
description,
27+
ResolutionPreset.low,
28+
);
29+
30+
expect(
31+
() => controller.debugCheckIsDisposed(),
32+
throwsAssertionError,
33+
);
34+
});
35+
});
36+
}
37+
38+
class MockCameraDescription extends CameraDescription {
39+
@override
40+
CameraLensDirection get lensDirection => CameraLensDirection.back;
41+
42+
@override
43+
String get name => 'back';
44+
}

0 commit comments

Comments
 (0)