Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit 03f992c

Browse files
committed
Revert "[camera] Remove deprecated Optional type (flutter-team-archive#6870)"
This reverts commit 3d8b73b.
1 parent ca483a7 commit 03f992c

6 files changed

Lines changed: 67 additions & 44 deletions

File tree

packages/camera/camera/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 0.10.3
1+
## 0.10.2
22

33
* Adds back use of Optional type.
44

packages/camera/camera/lib/src/camera_controller.dart

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ class CameraValue {
161161
bool? exposurePointSupported,
162162
bool? focusPointSupported,
163163
DeviceOrientation? deviceOrientation,
164-
DeviceOrientation? lockedCaptureOrientation,
165-
DeviceOrientation? recordingOrientation,
164+
Optional<DeviceOrientation>? lockedCaptureOrientation,
165+
Optional<DeviceOrientation>? recordingOrientation,
166166
bool? isPreviewPaused,
167-
DeviceOrientation? previewPauseOrientation,
167+
Optional<DeviceOrientation>? previewPauseOrientation,
168168
}) {
169169
return CameraValue(
170170
isInitialized: isInitialized ?? this.isInitialized,
@@ -358,8 +358,8 @@ class CameraController extends ValueNotifier<CameraValue> {
358358
await CameraPlatform.instance.pausePreview(_cameraId);
359359
value = value.copyWith(
360360
isPreviewPaused: true,
361-
previewPauseOrientation:
362-
value.lockedCaptureOrientation ?? value.deviceOrientation);
361+
previewPauseOrientation: Optional<DeviceOrientation>.of(
362+
value.lockedCaptureOrientation ?? value.deviceOrientation));
363363
} on PlatformException catch (e) {
364364
throw CameraException(e.code, e.message);
365365
}
@@ -372,8 +372,9 @@ class CameraController extends ValueNotifier<CameraValue> {
372372
}
373373
try {
374374
await CameraPlatform.instance.resumePreview(_cameraId);
375-
value =
376-
value.copyWith(isPreviewPaused: false, previewPauseOrientation: null);
375+
value = value.copyWith(
376+
isPreviewPaused: false,
377+
previewPauseOrientation: const Optional<DeviceOrientation>.absent());
377378
} on PlatformException catch (e) {
378379
throw CameraException(e.code, e.message);
379380
}
@@ -504,8 +505,8 @@ class CameraController extends ValueNotifier<CameraValue> {
504505
value = value.copyWith(
505506
isRecordingVideo: true,
506507
isRecordingPaused: false,
507-
recordingOrientation:
508-
value.lockedCaptureOrientation ?? value.deviceOrientation);
508+
recordingOrientation: Optional<DeviceOrientation>.of(
509+
value.lockedCaptureOrientation ?? value.deviceOrientation));
509510
} on PlatformException catch (e) {
510511
throw CameraException(e.code, e.message);
511512
}
@@ -525,8 +526,10 @@ class CameraController extends ValueNotifier<CameraValue> {
525526
try {
526527
final XFile file =
527528
await CameraPlatform.instance.stopVideoRecording(_cameraId);
528-
value =
529-
value.copyWith(isRecordingVideo: false, recordingOrientation: null);
529+
value = value.copyWith(
530+
isRecordingVideo: false,
531+
recordingOrientation: const Optional<DeviceOrientation>.absent(),
532+
);
530533
return file;
531534
} on PlatformException catch (e) {
532535
throw CameraException(e.code, e.message);
@@ -744,7 +747,8 @@ class CameraController extends ValueNotifier<CameraValue> {
744747
await CameraPlatform.instance.lockCaptureOrientation(
745748
_cameraId, orientation ?? value.deviceOrientation);
746749
value = value.copyWith(
747-
lockedCaptureOrientation: orientation ?? value.deviceOrientation);
750+
lockedCaptureOrientation: Optional<DeviceOrientation>.of(
751+
orientation ?? value.deviceOrientation));
748752
} on PlatformException catch (e) {
749753
throw CameraException(e.code, e.message);
750754
}
@@ -764,7 +768,8 @@ class CameraController extends ValueNotifier<CameraValue> {
764768
Future<void> unlockCaptureOrientation() async {
765769
try {
766770
await CameraPlatform.instance.unlockCaptureOrientation(_cameraId);
767-
value = value.copyWith(lockedCaptureOrientation: null);
771+
value = value.copyWith(
772+
lockedCaptureOrientation: const Optional<DeviceOrientation>.absent());
768773
} on PlatformException catch (e) {
769774
throw CameraException(e.code, e.message);
770775
}

packages/camera/camera/test/camera_preview_test.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
88
import 'package:flutter/services.dart';
99
import 'package:flutter/widgets.dart';
1010
import 'package:flutter_test/flutter_test.dart';
11+
import 'package:quiver/core.dart';
1112

1213
class FakeController extends ValueNotifier<CameraValue>
1314
implements CameraController {
@@ -132,8 +133,11 @@ void main() {
132133
isInitialized: true,
133134
isRecordingVideo: true,
134135
deviceOrientation: DeviceOrientation.portraitUp,
135-
lockedCaptureOrientation: DeviceOrientation.landscapeRight,
136-
recordingOrientation: DeviceOrientation.landscapeLeft,
136+
lockedCaptureOrientation:
137+
const Optional<DeviceOrientation>.fromNullable(
138+
DeviceOrientation.landscapeRight),
139+
recordingOrientation: const Optional<DeviceOrientation>.fromNullable(
140+
DeviceOrientation.landscapeLeft),
137141
previewSize: const Size(480, 640),
138142
);
139143

@@ -163,8 +167,11 @@ void main() {
163167
controller.value = controller.value.copyWith(
164168
isInitialized: true,
165169
deviceOrientation: DeviceOrientation.portraitUp,
166-
lockedCaptureOrientation: DeviceOrientation.landscapeRight,
167-
recordingOrientation: DeviceOrientation.landscapeLeft,
170+
lockedCaptureOrientation:
171+
const Optional<DeviceOrientation>.fromNullable(
172+
DeviceOrientation.landscapeRight),
173+
recordingOrientation: const Optional<DeviceOrientation>.fromNullable(
174+
DeviceOrientation.landscapeLeft),
168175
previewSize: const Size(480, 640),
169176
);
170177

@@ -194,7 +201,8 @@ void main() {
194201
controller.value = controller.value.copyWith(
195202
isInitialized: true,
196203
deviceOrientation: DeviceOrientation.portraitUp,
197-
recordingOrientation: DeviceOrientation.landscapeLeft,
204+
recordingOrientation: const Optional<DeviceOrientation>.fromNullable(
205+
DeviceOrientation.landscapeLeft),
198206
previewSize: const Size(480, 640),
199207
);
200208

packages/camera/camera/test/camera_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'package:flutter/widgets.dart';
1313
import 'package:flutter_test/flutter_test.dart';
1414
import 'package:mockito/mockito.dart';
1515
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
16+
import 'package:quiver/core.dart';
1617

1718
List<CameraDescription> get mockAvailableCameras => <CameraDescription>[
1819
const CameraDescription(
@@ -1190,7 +1191,8 @@ void main() {
11901191
cameraController.value = cameraController.value.copyWith(
11911192
isPreviewPaused: false,
11921193
deviceOrientation: DeviceOrientation.portraitUp,
1193-
lockedCaptureOrientation: DeviceOrientation.landscapeRight);
1194+
lockedCaptureOrientation:
1195+
Optional<DeviceOrientation>.of(DeviceOrientation.landscapeRight));
11941196

11951197
await cameraController.pausePreview();
11961198

packages/camera/camera_android/example/lib/camera_controller.dart

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ class CameraValue {
110110
bool? focusPointSupported,
111111
bool? isPreviewPaused,
112112
DeviceOrientation? deviceOrientation,
113-
DeviceOrientation? lockedCaptureOrientation,
114-
DeviceOrientation? recordingOrientation,
113+
Optional<DeviceOrientation>? lockedCaptureOrientation,
114+
Optional<DeviceOrientation>? recordingOrientation,
115115
bool? isPreviewPaused,
116-
DeviceOrientation? previewPauseOrientation,
116+
Optional<DeviceOrientation>? previewPauseOrientation,
117117
}) {
118118
return CameraValue(
119119
isInitialized: isInitialized ?? this.isInitialized,
@@ -263,15 +263,16 @@ class CameraController extends ValueNotifier<CameraValue> {
263263
await CameraPlatform.instance.pausePreview(_cameraId);
264264
value = value.copyWith(
265265
isPreviewPaused: true,
266-
previewPauseOrientation:
267-
value.lockedCaptureOrientation ?? value.deviceOrientation);
266+
previewPauseOrientation: Optional<DeviceOrientation>.of(
267+
value.lockedCaptureOrientation ?? value.deviceOrientation));
268268
}
269269

270270
/// Resumes the current camera preview
271271
Future<void> resumePreview() async {
272272
await CameraPlatform.instance.resumePreview(_cameraId);
273-
value =
274-
value.copyWith(isPreviewPaused: false, previewPauseOrientation: null);
273+
value = value.copyWith(
274+
isPreviewPaused: false,
275+
previewPauseOrientation: const Optional<DeviceOrientation>.absent());
275276
}
276277

277278
/// Captures an image and returns the file where it was saved.
@@ -314,8 +315,8 @@ class CameraController extends ValueNotifier<CameraValue> {
314315
isRecordingVideo: true,
315316
isRecordingPaused: false,
316317
isStreamingImages: streamCallback != null,
317-
recordingOrientation:
318-
value.lockedCaptureOrientation ?? value.deviceOrientation);
318+
recordingOrientation: Optional<DeviceOrientation>.of(
319+
value.lockedCaptureOrientation ?? value.deviceOrientation));
319320
}
320321

321322
/// Stops the video recording and returns the file where it was saved.
@@ -331,7 +332,7 @@ class CameraController extends ValueNotifier<CameraValue> {
331332
value = value.copyWith(
332333
isRecordingVideo: false,
333334
isRecordingPaused: false,
334-
recordingOrientation: null,
335+
recordingOrientation: const Optional<DeviceOrientation>.absent(),
335336
);
336337
return file;
337338
}
@@ -400,13 +401,16 @@ class CameraController extends ValueNotifier<CameraValue> {
400401
Future<void> lockCaptureOrientation() async {
401402
await CameraPlatform.instance
402403
.lockCaptureOrientation(_cameraId, value.deviceOrientation);
403-
value = value.copyWith(lockedCaptureOrientation: value.deviceOrientation);
404+
value = value.copyWith(
405+
lockedCaptureOrientation:
406+
Optional<DeviceOrientation>.of(value.deviceOrientation));
404407
}
405408

406409
/// Unlocks the capture orientation.
407410
Future<void> unlockCaptureOrientation() async {
408411
await CameraPlatform.instance.unlockCaptureOrientation(_cameraId);
409-
value = value.copyWith(lockedCaptureOrientation: null);
412+
value = value.copyWith(
413+
lockedCaptureOrientation: const Optional<DeviceOrientation>.absent());
410414
}
411415

412416
/// Sets the focus mode for taking pictures.

packages/camera/camera_avfoundation/example/lib/camera_controller.dart

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ class CameraValue {
109109
bool? exposurePointSupported,
110110
bool? focusPointSupported,
111111
DeviceOrientation? deviceOrientation,
112-
DeviceOrientation? lockedCaptureOrientation,
113-
DeviceOrientation? recordingOrientation,
112+
Optional<DeviceOrientation>? lockedCaptureOrientation,
113+
Optional<DeviceOrientation>? recordingOrientation,
114114
bool? isPreviewPaused,
115-
DeviceOrientation? previewPauseOrientation,
115+
Optional<DeviceOrientation>? previewPauseOrientation,
116116
}) {
117117
return CameraValue(
118118
isInitialized: isInitialized ?? this.isInitialized,
@@ -262,15 +262,16 @@ class CameraController extends ValueNotifier<CameraValue> {
262262
await CameraPlatform.instance.pausePreview(_cameraId);
263263
value = value.copyWith(
264264
isPreviewPaused: true,
265-
previewPauseOrientation:
266-
value.lockedCaptureOrientation ?? value.deviceOrientation);
265+
previewPauseOrientation: Optional<DeviceOrientation>.of(
266+
value.lockedCaptureOrientation ?? value.deviceOrientation));
267267
}
268268

269269
/// Resumes the current camera preview
270270
Future<void> resumePreview() async {
271271
await CameraPlatform.instance.resumePreview(_cameraId);
272-
value =
273-
value.copyWith(isPreviewPaused: false, previewPauseOrientation: null);
272+
value = value.copyWith(
273+
isPreviewPaused: false,
274+
previewPauseOrientation: const Optional<DeviceOrientation>.absent());
274275
}
275276

276277
/// Captures an image and returns the file where it was saved.
@@ -313,8 +314,8 @@ class CameraController extends ValueNotifier<CameraValue> {
313314
isRecordingVideo: true,
314315
isRecordingPaused: false,
315316
isStreamingImages: streamCallback != null,
316-
recordingOrientation:
317-
value.lockedCaptureOrientation ?? value.deviceOrientation);
317+
recordingOrientation: Optional<DeviceOrientation>.of(
318+
value.lockedCaptureOrientation ?? value.deviceOrientation));
318319
}
319320

320321
/// Stops the video recording and returns the file where it was saved.
@@ -329,7 +330,7 @@ class CameraController extends ValueNotifier<CameraValue> {
329330
await CameraPlatform.instance.stopVideoRecording(_cameraId);
330331
value = value.copyWith(
331332
isRecordingVideo: false,
332-
recordingOrientation: null,
333+
recordingOrientation: const Optional<DeviceOrientation>.absent(),
333334
);
334335
return file;
335336
}
@@ -398,13 +399,16 @@ class CameraController extends ValueNotifier<CameraValue> {
398399
Future<void> lockCaptureOrientation() async {
399400
await CameraPlatform.instance
400401
.lockCaptureOrientation(_cameraId, value.deviceOrientation);
401-
value = value.copyWith(lockedCaptureOrientation: value.deviceOrientation);
402+
value = value.copyWith(
403+
lockedCaptureOrientation:
404+
Optional<DeviceOrientation>.of(value.deviceOrientation));
402405
}
403406

404407
/// Unlocks the capture orientation.
405408
Future<void> unlockCaptureOrientation() async {
406409
await CameraPlatform.instance.unlockCaptureOrientation(_cameraId);
407-
value = value.copyWith(lockedCaptureOrientation: null);
410+
value = value.copyWith(
411+
lockedCaptureOrientation: const Optional<DeviceOrientation>.absent());
408412
}
409413

410414
/// Sets the focus mode for taking pictures.

0 commit comments

Comments
 (0)