Skip to content

[camera_web] Don't require enumerating cameras on web #8362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 10 additions & 2 deletions packages/camera/camera/lib/src/camera_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,13 @@ class CameraController extends ValueNotifier<CameraValue> {
.then((CameraInitializedEvent event) => event.focusPointSupported),
);
} on PlatformException catch (e) {
_unawaited(_deviceOrientationSubscription?.cancel());
_cameraId = kUninitializedCameraId;
throw CameraException(e.code, e.message);
} catch (e) {
_unawaited(_deviceOrientationSubscription?.cancel());
_cameraId = kUninitializedCameraId;
rethrow;
} finally {
initializeCompleter.complete();
}
Expand Down Expand Up @@ -882,8 +888,10 @@ class CameraController extends ValueNotifier<CameraValue> {
_unawaited(_deviceOrientationSubscription?.cancel());
_isDisposed = true;
super.dispose();
if (_initializeFuture != null) {
await _initializeFuture;
if (_initializeFuture == null) {
return;
}
if (_cameraId != kUninitializedCameraId) {
await CameraPlatform.instance.dispose(_cameraId);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ void main() {
);
});

testWidgets('missingMetadata', (WidgetTester tester) async {
expect(
CameraErrorCode.missingMetadata.toString(),
equals('cameraMissingMetadata'),
);
});

testWidgets('orientationNotSupported', (WidgetTester tester) async {
expect(
CameraErrorCode.orientationNotSupported.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ void main() {
'returns front '
'when the facing mode is user', (WidgetTester tester) async {
expect(
cameraService.mapFacingModeToLensDirection('user'),
mapFacingModeToLensDirection('user'),
equals(CameraLensDirection.front),
);
});
Expand All @@ -661,7 +661,7 @@ void main() {
'returns back '
'when the facing mode is environment', (WidgetTester tester) async {
expect(
cameraService.mapFacingModeToLensDirection('environment'),
mapFacingModeToLensDirection('environment'),
equals(CameraLensDirection.back),
);
});
Expand All @@ -670,7 +670,7 @@ void main() {
'returns external '
'when the facing mode is left', (WidgetTester tester) async {
expect(
cameraService.mapFacingModeToLensDirection('left'),
mapFacingModeToLensDirection('left'),
equals(CameraLensDirection.external),
);
});
Expand All @@ -679,7 +679,7 @@ void main() {
'returns external '
'when the facing mode is right', (WidgetTester tester) async {
expect(
cameraService.mapFacingModeToLensDirection('right'),
mapFacingModeToLensDirection('right'),
equals(CameraLensDirection.external),
);
});
Expand All @@ -690,7 +690,7 @@ void main() {
'returns user '
'when the facing mode is user', (WidgetTester tester) async {
expect(
cameraService.mapFacingModeToCameraType('user'),
mapFacingModeToCameraType('user'),
equals(CameraType.user),
);
});
Expand All @@ -699,7 +699,7 @@ void main() {
'returns environment '
'when the facing mode is environment', (WidgetTester tester) async {
expect(
cameraService.mapFacingModeToCameraType('environment'),
mapFacingModeToCameraType('environment'),
equals(CameraType.environment),
);
});
Expand All @@ -708,7 +708,7 @@ void main() {
'returns user '
'when the facing mode is left', (WidgetTester tester) async {
expect(
cameraService.mapFacingModeToCameraType('left'),
mapFacingModeToCameraType('left'),
equals(CameraType.user),
);
});
Expand All @@ -717,7 +717,7 @@ void main() {
'returns user '
'when the facing mode is right', (WidgetTester tester) async {
expect(
cameraService.mapFacingModeToCameraType('right'),
mapFacingModeToCameraType('right'),
equals(CameraType.user),
);
});
Expand All @@ -728,7 +728,7 @@ void main() {
'returns 4096x2160 '
'when the resolution preset is max', (WidgetTester tester) async {
expect(
cameraService.mapResolutionPresetToSize(ResolutionPreset.max),
mapResolutionPresetToSize(ResolutionPreset.max),
equals(const Size(4096, 2160)),
);
});
Expand All @@ -738,7 +738,7 @@ void main() {
'when the resolution preset is ultraHigh',
(WidgetTester tester) async {
expect(
cameraService.mapResolutionPresetToSize(ResolutionPreset.ultraHigh),
mapResolutionPresetToSize(ResolutionPreset.ultraHigh),
equals(const Size(4096, 2160)),
);
});
Expand All @@ -748,7 +748,7 @@ void main() {
'when the resolution preset is veryHigh',
(WidgetTester tester) async {
expect(
cameraService.mapResolutionPresetToSize(ResolutionPreset.veryHigh),
mapResolutionPresetToSize(ResolutionPreset.veryHigh),
equals(const Size(1920, 1080)),
);
});
Expand All @@ -757,7 +757,7 @@ void main() {
'returns 1280x720 '
'when the resolution preset is high', (WidgetTester tester) async {
expect(
cameraService.mapResolutionPresetToSize(ResolutionPreset.high),
mapResolutionPresetToSize(ResolutionPreset.high),
equals(const Size(1280, 720)),
);
});
Expand All @@ -766,7 +766,7 @@ void main() {
'returns 720x480 '
'when the resolution preset is medium', (WidgetTester tester) async {
expect(
cameraService.mapResolutionPresetToSize(ResolutionPreset.medium),
mapResolutionPresetToSize(ResolutionPreset.medium),
equals(const Size(720, 480)),
);
});
Expand All @@ -775,7 +775,7 @@ void main() {
'returns 320x240 '
'when the resolution preset is low', (WidgetTester tester) async {
expect(
cameraService.mapResolutionPresetToSize(ResolutionPreset.low),
mapResolutionPresetToSize(ResolutionPreset.low),
equals(const Size(320, 240)),
);
});
Expand All @@ -787,7 +787,7 @@ void main() {
'when the device orientation is portraitUp',
(WidgetTester tester) async {
expect(
cameraService.mapDeviceOrientationToOrientationType(
mapDeviceOrientationToOrientationType(
DeviceOrientation.portraitUp,
),
equals(OrientationType.portraitPrimary),
Expand All @@ -799,7 +799,7 @@ void main() {
'when the device orientation is landscapeLeft',
(WidgetTester tester) async {
expect(
cameraService.mapDeviceOrientationToOrientationType(
mapDeviceOrientationToOrientationType(
DeviceOrientation.landscapeLeft,
),
equals(OrientationType.landscapePrimary),
Expand All @@ -811,7 +811,7 @@ void main() {
'when the device orientation is portraitDown',
(WidgetTester tester) async {
expect(
cameraService.mapDeviceOrientationToOrientationType(
mapDeviceOrientationToOrientationType(
DeviceOrientation.portraitDown,
),
equals(OrientationType.portraitSecondary),
Expand All @@ -823,7 +823,7 @@ void main() {
'when the device orientation is landscapeRight',
(WidgetTester tester) async {
expect(
cameraService.mapDeviceOrientationToOrientationType(
mapDeviceOrientationToOrientationType(
DeviceOrientation.landscapeRight,
),
equals(OrientationType.landscapeSecondary),
Expand All @@ -837,7 +837,7 @@ void main() {
'when the orientation type is portraitPrimary',
(WidgetTester tester) async {
expect(
cameraService.mapOrientationTypeToDeviceOrientation(
mapOrientationTypeToDeviceOrientation(
OrientationType.portraitPrimary,
),
equals(DeviceOrientation.portraitUp),
Expand All @@ -849,7 +849,7 @@ void main() {
'when the orientation type is landscapePrimary',
(WidgetTester tester) async {
expect(
cameraService.mapOrientationTypeToDeviceOrientation(
mapOrientationTypeToDeviceOrientation(
OrientationType.landscapePrimary,
),
equals(DeviceOrientation.landscapeLeft),
Expand All @@ -861,7 +861,7 @@ void main() {
'when the orientation type is portraitSecondary',
(WidgetTester tester) async {
expect(
cameraService.mapOrientationTypeToDeviceOrientation(
mapOrientationTypeToDeviceOrientation(
OrientationType.portraitSecondary,
),
equals(DeviceOrientation.portraitDown),
Expand All @@ -873,7 +873,7 @@ void main() {
'when the orientation type is portraitSecondary',
(WidgetTester tester) async {
expect(
cameraService.mapOrientationTypeToDeviceOrientation(
mapOrientationTypeToDeviceOrientation(
OrientationType.portraitSecondary,
),
equals(DeviceOrientation.portraitDown),
Expand All @@ -885,7 +885,7 @@ void main() {
'when the orientation type is landscapeSecondary',
(WidgetTester tester) async {
expect(
cameraService.mapOrientationTypeToDeviceOrientation(
mapOrientationTypeToDeviceOrientation(
OrientationType.landscapeSecondary,
),
equals(DeviceOrientation.landscapeRight),
Expand All @@ -896,7 +896,7 @@ void main() {
'returns portraitUp '
'for an unknown orientation type', (WidgetTester tester) async {
expect(
cameraService.mapOrientationTypeToDeviceOrientation(
mapOrientationTypeToDeviceOrientation(
'unknown',
),
equals(DeviceOrientation.portraitUp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ void main() {
return MediaTrackSettings(facingMode: 'environment');
}.toJS;

when(() => cameraService.mapFacingModeToLensDirection('environment'))
when(() => mapFacingModeToLensDirection('environment'))
.thenReturn(CameraLensDirection.external);

expect(
Expand Down
Loading