Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
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
Original file line number Diff line number Diff line change
Expand Up @@ -684,11 +684,54 @@ void main() {
);
});

testWidgets('dispose throws UnimplementedError', (tester) async {
expect(
() => CameraPlatform.instance.dispose(cameraId),
throwsUnimplementedError,
);
group('dispose', () {
testWidgets(
'throws CameraException '
'with notFound error '
'if the camera does not exist', (tester) async {
expect(
() => CameraPlatform.instance.dispose(cameraId),
throwsA(
isA<CameraException>().having(
(e) => e.code,
'code',
CameraErrorCodes.notFound,
),
),
);
});

testWidgets('disposes the correct camera', (tester) async {
const firstCameraId = 0;
const secondCameraId = 1;

final firstCamera = MockCamera();
final secondCamera = MockCamera();

when(firstCamera.dispose).thenAnswer((_) => Future.value());
when(secondCamera.dispose).thenAnswer((_) => Future.value());

// Save cameras in the camera plugin.
(CameraPlatform.instance as CameraPlugin).cameras.addAll({
firstCameraId: firstCamera,
secondCameraId: secondCamera,
});

// Dispose the first camera.
await CameraPlatform.instance.dispose(firstCameraId);

// The first camera should be disposed.
verify(firstCamera.dispose).called(1);
verifyNever(secondCamera.dispose);

// The first camera should be removed from the camera plugin.
expect(
(CameraPlatform.instance as CameraPlugin).cameras,
equals({
secondCameraId: secondCamera,
}),
);
});
});

group('getCamera', () {
Expand Down
5 changes: 3 additions & 2 deletions packages/camera/camera_web/lib/src/camera_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,9 @@ class CameraPlugin extends CameraPlatform {
}

@override
Future<void> dispose(int cameraId) {
throw UnimplementedError('dispose() is not implemented.');
Future<void> dispose(int cameraId) async {
getCamera(cameraId).dispose();
cameras.remove(cameraId);
}

/// Returns a media video stream for the device with the given [deviceId].
Expand Down