Skip to content

Commit 7e9c79b

Browse files
authored
[camera] NNBD migration of the camera plugin (flutter#3533)
* Migrate camera_platform_interface to null safety * Exclude camera_platform_interface from all plugins script * Convert CameraId in test to non-nullable * Migrate to nullsafety * Attempt to fix dependency problem building all plugins * Update version information * Fix type * Make exposureMode and focusMode non-nullable * Mark google_maps_flutter as non-NNBD * Update dependencies * Added missing entry to CHANGELOG.md * Rebased on master
1 parent 57a40bf commit 7e9c79b

File tree

13 files changed

+270
-131
lines changed

13 files changed

+270
-131
lines changed

packages/camera/camera/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.8.0-nullsafety
2+
3+
* Migrated to null safety.
4+
15
## 0.7.0+4
26

37
* Fix crash when taking picture with orientation lock
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
12
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
23
#include "Generated.xcconfig"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
12
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
23
#include "Generated.xcconfig"

packages/camera/camera/example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@
147147
97C146EC1CF9000F007C117D /* Resources */,
148148
9705A1C41CF9048500538489 /* Embed Frameworks */,
149149
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
150-
FE224661708E6DA2A0F8B952 /* [CP] Embed Pods Frameworks */,
151150
);
152151
buildRules = (
153152
);
@@ -252,24 +251,6 @@
252251
shellPath = /bin/sh;
253252
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
254253
};
255-
FE224661708E6DA2A0F8B952 /* [CP] Embed Pods Frameworks */ = {
256-
isa = PBXShellScriptBuildPhase;
257-
buildActionMask = 2147483647;
258-
files = (
259-
);
260-
inputPaths = (
261-
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
262-
"${PODS_ROOT}/../Flutter/Flutter.framework",
263-
);
264-
name = "[CP] Embed Pods Frameworks";
265-
outputPaths = (
266-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
267-
);
268-
runOnlyForDeploymentPostprocessing = 0;
269-
shellPath = /bin/sh;
270-
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
271-
showEnvVarsInLog = 0;
272-
};
273254
/* End PBXShellScriptBuildPhase section */
274255

275256
/* Begin PBXSourcesBuildPhase section */

packages/camera/camera/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ Future<List<CameraDescription>> availableCameras() async {
3232
class CameraValue {
3333
/// Creates a new camera controller state.
3434
const CameraValue({
35-
this.isInitialized,
35+
required this.isInitialized,
3636
this.errorDescription,
3737
this.previewSize,
38-
this.isRecordingVideo,
39-
this.isTakingPicture,
40-
this.isStreamingImages,
41-
bool isRecordingPaused,
42-
this.flashMode,
43-
this.exposureMode,
44-
this.focusMode,
45-
this.exposurePointSupported,
46-
this.focusPointSupported,
47-
this.deviceOrientation,
38+
required this.isRecordingVideo,
39+
required this.isTakingPicture,
40+
required this.isStreamingImages,
41+
required bool isRecordingPaused,
42+
required this.flashMode,
43+
required this.exposureMode,
44+
required this.focusMode,
45+
required this.exposurePointSupported,
46+
required this.focusPointSupported,
47+
required this.deviceOrientation,
4848
this.lockedCaptureOrientation,
4949
this.recordingOrientation,
5050
}) : _isRecordingPaused = isRecordingPaused;
@@ -58,7 +58,9 @@ class CameraValue {
5858
isStreamingImages: false,
5959
isRecordingPaused: false,
6060
flashMode: FlashMode.auto,
61+
exposureMode: ExposureMode.auto,
6162
exposurePointSupported: false,
63+
focusMode: FocusMode.auto,
6264
focusPointSupported: false,
6365
deviceOrientation: DeviceOrientation.portraitUp,
6466
);
@@ -84,17 +86,17 @@ class CameraValue {
8486
///
8587
/// This is null while the controller is not in an error state.
8688
/// When [hasError] is true this contains the error description.
87-
final String errorDescription;
89+
final String? errorDescription;
8890

8991
/// The size of the preview in pixels.
9092
///
91-
/// Is `null` until [isInitialized] is `true`.
92-
final Size previewSize;
93+
/// Is `null` until [isInitialized] is `true`.
94+
final Size? previewSize;
9395

9496
/// Convenience getter for `previewSize.width / previewSize.height`.
9597
///
9698
/// Can only be called when [initialize] is done.
97-
double get aspectRatio => previewSize.width / previewSize.height;
99+
double get aspectRatio => previewSize!.width / previewSize!.height;
98100

99101
/// Whether the controller is in an error state.
100102
///
@@ -120,34 +122,34 @@ class CameraValue {
120122
final DeviceOrientation deviceOrientation;
121123

122124
/// The currently locked capture orientation.
123-
final DeviceOrientation lockedCaptureOrientation;
125+
final DeviceOrientation? lockedCaptureOrientation;
124126

125127
/// Whether the capture orientation is currently locked.
126128
bool get isCaptureOrientationLocked => lockedCaptureOrientation != null;
127129

128130
/// The orientation of the currently running video recording.
129-
final DeviceOrientation recordingOrientation;
131+
final DeviceOrientation? recordingOrientation;
130132

131133
/// Creates a modified copy of the object.
132134
///
133135
/// Explicitly specified fields get the specified value, all other fields get
134136
/// the same value of the current object.
135137
CameraValue copyWith({
136-
bool isInitialized,
137-
bool isRecordingVideo,
138-
bool isTakingPicture,
139-
bool isStreamingImages,
140-
String errorDescription,
141-
Size previewSize,
142-
bool isRecordingPaused,
143-
FlashMode flashMode,
144-
ExposureMode exposureMode,
145-
FocusMode focusMode,
146-
bool exposurePointSupported,
147-
bool focusPointSupported,
148-
DeviceOrientation deviceOrientation,
149-
Optional<DeviceOrientation> lockedCaptureOrientation,
150-
Optional<DeviceOrientation> recordingOrientation,
138+
bool? isInitialized,
139+
bool? isRecordingVideo,
140+
bool? isTakingPicture,
141+
bool? isStreamingImages,
142+
String? errorDescription,
143+
Size? previewSize,
144+
bool? isRecordingPaused,
145+
FlashMode? flashMode,
146+
ExposureMode? exposureMode,
147+
FocusMode? focusMode,
148+
bool? exposurePointSupported,
149+
bool? focusPointSupported,
150+
DeviceOrientation? deviceOrientation,
151+
Optional<DeviceOrientation>? lockedCaptureOrientation,
152+
Optional<DeviceOrientation>? recordingOrientation,
151153
}) {
152154
return CameraValue(
153155
isInitialized: isInitialized ?? this.isInitialized,
@@ -225,13 +227,17 @@ class CameraController extends ValueNotifier<CameraValue> {
225227
/// The [ImageFormatGroup] describes the output of the raw image format.
226228
///
227229
/// When null the imageFormat will fallback to the platforms default.
228-
final ImageFormatGroup imageFormatGroup;
230+
final ImageFormatGroup? imageFormatGroup;
231+
232+
/// The id of a camera that hasn't been initialized.
233+
@visibleForTesting
234+
static const int kUninitializedCameraId = -1;
235+
int _cameraId = kUninitializedCameraId;
229236

230-
int _cameraId;
231237
bool _isDisposed = false;
232-
StreamSubscription<dynamic> _imageStreamSubscription;
233-
FutureOr<bool> _initCalled;
234-
StreamSubscription _deviceOrientationSubscription;
238+
StreamSubscription<dynamic>? _imageStreamSubscription;
239+
FutureOr<bool>? _initCalled;
240+
StreamSubscription? _deviceOrientationSubscription;
235241

236242
/// Checks whether [CameraController.dispose] has completed successfully.
237243
///
@@ -278,7 +284,7 @@ class CameraController extends ValueNotifier<CameraValue> {
278284

279285
await CameraPlatform.instance.initializeCamera(
280286
_cameraId,
281-
imageFormatGroup: imageFormatGroup,
287+
imageFormatGroup: imageFormatGroup ?? ImageFormatGroup.unknown,
282288
);
283289

284290
value = value.copyWith(
@@ -422,7 +428,7 @@ class CameraController extends ValueNotifier<CameraValue> {
422428
throw CameraException(e.code, e.message);
423429
}
424430

425-
await _imageStreamSubscription.cancel();
431+
await _imageStreamSubscription?.cancel();
426432
_imageStreamSubscription = null;
427433
}
428434

@@ -583,12 +589,16 @@ class CameraController extends ValueNotifier<CameraValue> {
583589
}
584590

585591
/// Sets the exposure point for automatically determining the exposure value.
586-
Future<void> setExposurePoint(Offset point) async {
592+
///
593+
/// Supplying a `null` value will reset the exposure point to it's default
594+
/// value.
595+
Future<void> setExposurePoint(Offset? point) async {
587596
if (point != null &&
588597
(point.dx < 0 || point.dx > 1 || point.dy < 0 || point.dy > 1)) {
589598
throw ArgumentError(
590599
'The values of point should be anywhere between (0,0) and (1,1).');
591600
}
601+
592602
try {
593603
await CameraPlatform.instance.setExposurePoint(
594604
_cameraId,
@@ -682,7 +692,7 @@ class CameraController extends ValueNotifier<CameraValue> {
682692
/// Locks the capture orientation.
683693
///
684694
/// If [orientation] is omitted, the current device orientation is used.
685-
Future<void> lockCaptureOrientation([DeviceOrientation orientation]) async {
695+
Future<void> lockCaptureOrientation([DeviceOrientation? orientation]) async {
686696
try {
687697
await CameraPlatform.instance.lockCaptureOrientation(
688698
_cameraId, orientation ?? value.deviceOrientation);
@@ -715,7 +725,10 @@ class CameraController extends ValueNotifier<CameraValue> {
715725
}
716726

717727
/// Sets the focus point for automatically determining the focus value.
718-
Future<void> setFocusPoint(Offset point) async {
728+
///
729+
/// Supplying a `null` value will reset the focus point to it's default
730+
/// value.
731+
Future<void> setFocusPoint(Offset? point) async {
719732
if (point != null &&
720733
(point.dx < 0 || point.dx > 1 || point.dy < 0 || point.dy > 1)) {
721734
throw ArgumentError(

packages/camera/camera/lib/src/camera_image.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ class Plane {
2626
/// The distance between adjacent pixel samples on Android, in bytes.
2727
///
2828
/// Will be `null` on iOS.
29-
final int bytesPerPixel;
29+
final int? bytesPerPixel;
3030

3131
/// The row stride for this color plane, in bytes.
3232
final int bytesPerRow;
3333

3434
/// Height of the pixel buffer on iOS.
3535
///
3636
/// Will be `null` on Android
37-
final int height;
37+
final int? height;
3838

3939
/// Width of the pixel buffer on iOS.
4040
///
4141
/// Will be `null` on Android.
42-
final int width;
42+
final int? width;
4343
}
4444

4545
/// Describes how pixels are represented in an image.

packages/camera/camera/lib/src/camera_preview.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CameraPreview extends StatelessWidget {
1717
final CameraController controller;
1818

1919
/// A widget to overlay on top of the camera preview
20-
final Widget child;
20+
final Widget? child;
2121

2222
@override
2323
Widget build(BuildContext context) {
@@ -43,7 +43,7 @@ class CameraPreview extends StatelessWidget {
4343

4444
DeviceOrientation _getApplicableOrientation() {
4545
return controller.value.isRecordingVideo
46-
? controller.value.recordingOrientation
46+
? controller.value.recordingOrientation!
4747
: (controller.value.lockedCaptureOrientation ??
4848
controller.value.deviceOrientation);
4949
}
@@ -61,6 +61,6 @@ class CameraPreview extends StatelessWidget {
6161
DeviceOrientation.portraitDown: 2,
6262
DeviceOrientation.landscapeRight: 3,
6363
};
64-
return turns[_getApplicableOrientation()] + platformOffset;
64+
return turns[_getApplicableOrientation()]! + platformOffset;
6565
}
6666
}

packages/camera/camera/pubspec.yaml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@ name: camera
22
description: A Flutter plugin for getting information about and controlling the
33
camera on Android and iOS. Supports previewing the camera feed, capturing images, capturing video,
44
and streaming image buffers to dart.
5-
version: 0.7.0+4
5+
version: 0.8.0-nullsafety
66
homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera
77

88
dependencies:
99
flutter:
1010
sdk: flutter
11-
camera_platform_interface: ^1.5.0
12-
pedantic: ^1.8.0
13-
quiver: ^2.1.5
11+
12+
camera_platform_interface: ^2.0.0-nullsafety
13+
14+
pedantic: ^1.10.0
15+
quiver: ^3.0.0-nullsafety.3
1416

1517
dev_dependencies:
16-
path_provider: ^0.5.0
17-
video_player: ^0.10.0
18+
video_player: ^2.0.0-nullsafety.7
1819
flutter_test:
1920
sdk: flutter
2021
flutter_driver:
2122
sdk: flutter
22-
mockito: ^4.1.3
23-
plugin_platform_interface: ^1.0.3
23+
mockito: ^5.0.0-nullsafety.5
24+
plugin_platform_interface: ^1.1.0-nullsafety.2
2425

2526
flutter:
2627
plugin:
@@ -32,5 +33,5 @@ flutter:
3233
pluginClass: CameraPlugin
3334

3435
environment:
35-
sdk: ">=2.7.0 <3.0.0"
36-
flutter: ">=1.12.13+hotfix.5"
36+
sdk: '>=2.12.0-0 <3.0.0'
37+
flutter: ">=1.22.0"

0 commit comments

Comments
 (0)