Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[Camera] Made CameraController.isDisposed publicly accessible. Added unit Tests for the new implementation. #3193

Merged
merged 8 commits into from
Nov 10, 2020
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
4 changes: 4 additions & 0 deletions packages/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.8+15

* Added the `debugCheckIsDisposed` method which can be used in debug mode to validate if the `CameraController` class has been disposed.

## 0.5.8+14

* Changed the order of the setters for `mediaRecorder` in `MediaRecorderBuilder.java` to make it more readable.
Expand Down
7 changes: 7 additions & 0 deletions packages/camera/lib/camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,13 @@ class CameraController extends ValueNotifier<CameraValue> {
StreamSubscription<dynamic> _imageStreamSubscription;
Completer<void> _creatingCompleter;

/// Checks whether [CameraController.dispose] has completed successfully.
///
/// This is a no-op when asserts are disabled.
void debugCheckIsDisposed() {
assert(_isDisposed);
}

/// Initializes the camera on the device.
///
/// Throws a [CameraException] if the initialization fails.
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera
description: A Flutter plugin for getting information about and controlling the
camera on Android and iOS. Supports previewing the camera feed, capturing images, capturing video,
and streaming image buffers to dart.
version: 0.5.8+14
version: 0.5.8+15
homepage: https://github.com/flutter/plugins/tree/master/packages/camera

dependencies:
Expand Down
44 changes: 44 additions & 0 deletions packages/camera/test/camera_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2017 The Chromium 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 'package:camera/camera.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
group('camera', () {
test('debugCheckIsDisposed should not throw assertion error when disposed',
() {
final MockCameraDescription description = MockCameraDescription();
final CameraController controller = CameraController(
description,
ResolutionPreset.low,
);

controller.dispose();

expect(controller.debugCheckIsDisposed, returnsNormally);
});

test('debugCheckIsDisposed should throw assertion error when not disposed',
() {
final MockCameraDescription description = MockCameraDescription();
final CameraController controller = CameraController(
description,
ResolutionPreset.low,
);

expect(
() => controller.debugCheckIsDisposed(),
throwsAssertionError,
);
});
});
}

class MockCameraDescription extends CameraDescription {
@override
CameraLensDirection get lensDirection => CameraLensDirection.back;

@override
String get name => 'back';
}