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

[camera] Remove deprecated Optional type #6870

Merged
merged 6 commits into from
Dec 20, 2022
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/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.1

* Remove usage of deprecated quiver Optional type.

## 0.10.0+5

* Updates code for stricter lint checks.
Expand Down
44 changes: 16 additions & 28 deletions packages/camera/camera/lib/src/camera_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:camera_platform_interface/camera_platform_interface.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:quiver/core.dart';

import '../camera.dart';

Expand Down Expand Up @@ -161,10 +160,10 @@ class CameraValue {
bool? exposurePointSupported,
bool? focusPointSupported,
DeviceOrientation? deviceOrientation,
Optional<DeviceOrientation>? lockedCaptureOrientation,
Optional<DeviceOrientation>? recordingOrientation,
DeviceOrientation? lockedCaptureOrientation,
DeviceOrientation? recordingOrientation,
bool? isPreviewPaused,
Optional<DeviceOrientation>? previewPauseOrientation,
DeviceOrientation? previewPauseOrientation,
}) {
return CameraValue(
isInitialized: isInitialized ?? this.isInitialized,
Expand All @@ -181,16 +180,12 @@ class CameraValue {
exposurePointSupported ?? this.exposurePointSupported,
focusPointSupported: focusPointSupported ?? this.focusPointSupported,
deviceOrientation: deviceOrientation ?? this.deviceOrientation,
lockedCaptureOrientation: lockedCaptureOrientation == null
? this.lockedCaptureOrientation
: lockedCaptureOrientation.orNull,
recordingOrientation: recordingOrientation == null
? this.recordingOrientation
: recordingOrientation.orNull,
lockedCaptureOrientation:
lockedCaptureOrientation ?? this.lockedCaptureOrientation,
recordingOrientation: recordingOrientation ?? this.recordingOrientation,
isPreviewPaused: isPreviewPaused ?? this.isPreviewPaused,
previewPauseOrientation: previewPauseOrientation == null
? this.previewPauseOrientation
: previewPauseOrientation.orNull,
previewPauseOrientation:
previewPauseOrientation ?? this.previewPauseOrientation,
);
}

Expand Down Expand Up @@ -358,8 +353,8 @@ class CameraController extends ValueNotifier<CameraValue> {
await CameraPlatform.instance.pausePreview(_cameraId);
value = value.copyWith(
isPreviewPaused: true,
previewPauseOrientation: Optional<DeviceOrientation>.of(
value.lockedCaptureOrientation ?? value.deviceOrientation));
previewPauseOrientation:
value.lockedCaptureOrientation ?? value.deviceOrientation);
} on PlatformException catch (e) {
throw CameraException(e.code, e.message);
}
Expand All @@ -372,9 +367,7 @@ class CameraController extends ValueNotifier<CameraValue> {
}
try {
await CameraPlatform.instance.resumePreview(_cameraId);
value = value.copyWith(
isPreviewPaused: false,
previewPauseOrientation: const Optional<DeviceOrientation>.absent());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this seems to break camera orientation changes while preview is paused. Since copyWith can no longer be told to clear previewPauseOrientation, it keeps its stale value and locks the CameraPreview widget in the old orientation until the next pausePreview call.

A few of the other fields appear to be nullable as well, but I haven't looked closely to see if there are any other regressions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok, sorry I didn't realize this. I may have to do some refactoring where Optional<DeviceOrientation> was used. Thanks for letting me know!

value = value.copyWith(isPreviewPaused: false);
} on PlatformException catch (e) {
throw CameraException(e.code, e.message);
}
Expand Down Expand Up @@ -505,8 +498,8 @@ class CameraController extends ValueNotifier<CameraValue> {
value = value.copyWith(
isRecordingVideo: true,
isRecordingPaused: false,
recordingOrientation: Optional<DeviceOrientation>.of(
value.lockedCaptureOrientation ?? value.deviceOrientation));
recordingOrientation:
value.lockedCaptureOrientation ?? value.deviceOrientation);
} on PlatformException catch (e) {
throw CameraException(e.code, e.message);
}
Expand All @@ -526,10 +519,7 @@ class CameraController extends ValueNotifier<CameraValue> {
try {
final XFile file =
await CameraPlatform.instance.stopVideoRecording(_cameraId);
value = value.copyWith(
isRecordingVideo: false,
recordingOrientation: const Optional<DeviceOrientation>.absent(),
);
value = value.copyWith(isRecordingVideo: false);
return file;
} on PlatformException catch (e) {
throw CameraException(e.code, e.message);
Expand Down Expand Up @@ -747,8 +737,7 @@ class CameraController extends ValueNotifier<CameraValue> {
await CameraPlatform.instance.lockCaptureOrientation(
_cameraId, orientation ?? value.deviceOrientation);
value = value.copyWith(
lockedCaptureOrientation: Optional<DeviceOrientation>.of(
orientation ?? value.deviceOrientation));
lockedCaptureOrientation: orientation ?? value.deviceOrientation);
} on PlatformException catch (e) {
throw CameraException(e.code, e.message);
}
Expand All @@ -768,8 +757,7 @@ class CameraController extends ValueNotifier<CameraValue> {
Future<void> unlockCaptureOrientation() async {
try {
await CameraPlatform.instance.unlockCaptureOrientation(_cameraId);
value = value.copyWith(
lockedCaptureOrientation: const Optional<DeviceOrientation>.absent());
value = value.copyWith();
} on PlatformException catch (e) {
throw CameraException(e.code, e.message);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A Flutter plugin for controlling the camera. Supports previewing
Dart.
repository: https://github.com/flutter/plugins/tree/main/packages/camera/camera
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.10.0+5
version: 0.10.1

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down
18 changes: 5 additions & 13 deletions packages/camera/camera/test/camera_preview_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:quiver/core.dart';

class FakeController extends ValueNotifier<CameraValue>
implements CameraController {
Expand Down Expand Up @@ -133,11 +132,8 @@ void main() {
isInitialized: true,
isRecordingVideo: true,
deviceOrientation: DeviceOrientation.portraitUp,
lockedCaptureOrientation:
const Optional<DeviceOrientation>.fromNullable(
DeviceOrientation.landscapeRight),
recordingOrientation: const Optional<DeviceOrientation>.fromNullable(
DeviceOrientation.landscapeLeft),
lockedCaptureOrientation: DeviceOrientation.landscapeRight,
recordingOrientation: DeviceOrientation.landscapeLeft,
previewSize: const Size(480, 640),
);

Expand Down Expand Up @@ -167,11 +163,8 @@ void main() {
controller.value = controller.value.copyWith(
isInitialized: true,
deviceOrientation: DeviceOrientation.portraitUp,
lockedCaptureOrientation:
const Optional<DeviceOrientation>.fromNullable(
DeviceOrientation.landscapeRight),
recordingOrientation: const Optional<DeviceOrientation>.fromNullable(
DeviceOrientation.landscapeLeft),
lockedCaptureOrientation: DeviceOrientation.landscapeRight,
recordingOrientation: DeviceOrientation.landscapeLeft,
previewSize: const Size(480, 640),
);

Expand Down Expand Up @@ -201,8 +194,7 @@ void main() {
controller.value = controller.value.copyWith(
isInitialized: true,
deviceOrientation: DeviceOrientation.portraitUp,
recordingOrientation: const Optional<DeviceOrientation>.fromNullable(
DeviceOrientation.landscapeLeft),
recordingOrientation: DeviceOrientation.landscapeLeft,
previewSize: const Size(480, 640),
);

Expand Down
4 changes: 1 addition & 3 deletions packages/camera/camera/test/camera_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'package:quiver/core.dart';

List<CameraDescription> get mockAvailableCameras => <CameraDescription>[
const CameraDescription(
Expand Down Expand Up @@ -1191,8 +1190,7 @@ void main() {
cameraController.value = cameraController.value.copyWith(
isPreviewPaused: false,
deviceOrientation: DeviceOrientation.portraitUp,
lockedCaptureOrientation:
Optional<DeviceOrientation>.of(DeviceOrientation.landscapeRight));
lockedCaptureOrientation: DeviceOrientation.landscapeRight);

await cameraController.pausePreview();

Expand Down
4 changes: 4 additions & 0 deletions packages/camera/camera_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.2

* Remove usage of deprecated quiver Optional type.

## 0.10.1

* Implements an option to also stream when recording a video.
Expand Down
40 changes: 14 additions & 26 deletions packages/camera/camera_android/example/lib/camera_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:camera_platform_interface/camera_platform_interface.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:quiver/core.dart';

/// The state of a [CameraController].
class CameraValue {
Expand Down Expand Up @@ -109,10 +108,10 @@ class CameraValue {
bool? exposurePointSupported,
bool? focusPointSupported,
DeviceOrientation? deviceOrientation,
Optional<DeviceOrientation>? lockedCaptureOrientation,
Optional<DeviceOrientation>? recordingOrientation,
DeviceOrientation? lockedCaptureOrientation,
DeviceOrientation? recordingOrientation,
bool? isPreviewPaused,
Optional<DeviceOrientation>? previewPauseOrientation,
DeviceOrientation? previewPauseOrientation,
}) {
return CameraValue(
isInitialized: isInitialized ?? this.isInitialized,
Expand All @@ -125,16 +124,12 @@ class CameraValue {
exposureMode: exposureMode ?? this.exposureMode,
focusMode: focusMode ?? this.focusMode,
deviceOrientation: deviceOrientation ?? this.deviceOrientation,
lockedCaptureOrientation: lockedCaptureOrientation == null
? this.lockedCaptureOrientation
: lockedCaptureOrientation.orNull,
recordingOrientation: recordingOrientation == null
? this.recordingOrientation
: recordingOrientation.orNull,
lockedCaptureOrientation:
lockedCaptureOrientation ?? this.lockedCaptureOrientation,
recordingOrientation: recordingOrientation ?? this.recordingOrientation,
isPreviewPaused: isPreviewPaused ?? this.isPreviewPaused,
previewPauseOrientation: previewPauseOrientation == null
? this.previewPauseOrientation
: previewPauseOrientation.orNull,
previewPauseOrientation:
previewPauseOrientation ?? this.previewPauseOrientation,
);
}

Expand Down Expand Up @@ -262,16 +257,14 @@ class CameraController extends ValueNotifier<CameraValue> {
await CameraPlatform.instance.pausePreview(_cameraId);
value = value.copyWith(
isPreviewPaused: true,
previewPauseOrientation: Optional<DeviceOrientation>.of(
value.lockedCaptureOrientation ?? value.deviceOrientation));
previewPauseOrientation:
value.lockedCaptureOrientation ?? value.deviceOrientation);
}

/// Resumes the current camera preview
Future<void> resumePreview() async {
await CameraPlatform.instance.resumePreview(_cameraId);
value = value.copyWith(
isPreviewPaused: false,
previewPauseOrientation: const Optional<DeviceOrientation>.absent());
value = value.copyWith(isPreviewPaused: false);
}

/// Captures an image and returns the file where it was saved.
Expand Down Expand Up @@ -314,8 +307,8 @@ class CameraController extends ValueNotifier<CameraValue> {
isRecordingVideo: true,
isRecordingPaused: false,
isStreamingImages: streamCallback != null,
recordingOrientation: Optional<DeviceOrientation>.of(
value.lockedCaptureOrientation ?? value.deviceOrientation));
recordingOrientation:
value.lockedCaptureOrientation ?? value.deviceOrientation);
}

/// Stops the video recording and returns the file where it was saved.
Expand All @@ -331,7 +324,6 @@ class CameraController extends ValueNotifier<CameraValue> {
value = value.copyWith(
isRecordingVideo: false,
isRecordingPaused: false,
recordingOrientation: const Optional<DeviceOrientation>.absent(),
);
return file;
}
Expand Down Expand Up @@ -400,16 +392,12 @@ class CameraController extends ValueNotifier<CameraValue> {
Future<void> lockCaptureOrientation() async {
await CameraPlatform.instance
.lockCaptureOrientation(_cameraId, value.deviceOrientation);
value = value.copyWith(
lockedCaptureOrientation:
Optional<DeviceOrientation>.of(value.deviceOrientation));
value = value.copyWith(lockedCaptureOrientation: value.deviceOrientation);
}

/// Unlocks the capture orientation.
Future<void> unlockCaptureOrientation() async {
await CameraPlatform.instance.unlockCaptureOrientation(_cameraId);
value = value.copyWith(
lockedCaptureOrientation: const Optional<DeviceOrientation>.absent());
}

/// Sets the focus mode for taking pictures.
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera_android
description: Android implementation of the camera plugin.
repository: https://github.com/flutter/plugins/tree/main/packages/camera/camera_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.10.1
version: 0.10.2

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/camera/camera_avfoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.10

* Remove usage of deprecated quiver Optional type.

## 0.9.9

* Implements option to also stream when recording a video.
Expand Down
Loading