Thanks to visit codestin.com
Credit goes to github.com

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

[camera] NNBD migration of the camera plugin #3533

Merged
merged 12 commits into from
Feb 15, 2021
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.8.0-nullsafety

* Migrated to null safety.

## 0.7.0+4

* Fix crash when taking picture with orientation lock
Expand Down
1 change: 1 addition & 0 deletions packages/camera/camera/example/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
FE224661708E6DA2A0F8B952 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -252,24 +251,6 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
};
FE224661708E6DA2A0F8B952 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/../Flutter/Flutter.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 55 additions & 42 deletions packages/camera/camera/lib/src/camera_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ Future<List<CameraDescription>> availableCameras() async {
class CameraValue {
/// Creates a new camera controller state.
const CameraValue({
this.isInitialized,
required this.isInitialized,
this.errorDescription,
this.previewSize,
this.isRecordingVideo,
this.isTakingPicture,
this.isStreamingImages,
bool isRecordingPaused,
this.flashMode,
this.exposureMode,
this.focusMode,
this.exposurePointSupported,
this.focusPointSupported,
this.deviceOrientation,
required this.isRecordingVideo,
required this.isTakingPicture,
required this.isStreamingImages,
required bool isRecordingPaused,
required this.flashMode,
required this.exposureMode,
required this.focusMode,
required this.exposurePointSupported,
required this.focusPointSupported,
required this.deviceOrientation,
this.lockedCaptureOrientation,
this.recordingOrientation,
}) : _isRecordingPaused = isRecordingPaused;
Expand All @@ -58,7 +58,9 @@ class CameraValue {
isStreamingImages: false,
isRecordingPaused: false,
flashMode: FlashMode.auto,
exposureMode: ExposureMode.auto,
exposurePointSupported: false,
focusMode: FocusMode.auto,
focusPointSupported: false,
deviceOrientation: DeviceOrientation.portraitUp,
);
Expand All @@ -84,17 +86,17 @@ class CameraValue {
///
/// This is null while the controller is not in an error state.
/// When [hasError] is true this contains the error description.
final String errorDescription;
final String? errorDescription;

/// The size of the preview in pixels.
///
/// Is `null` until [isInitialized] is `true`.
final Size previewSize;
/// Is `null` until [isInitialized] is `true`.
final Size? previewSize;

/// Convenience getter for `previewSize.width / previewSize.height`.
///
/// Can only be called when [initialize] is done.
double get aspectRatio => previewSize.width / previewSize.height;
double get aspectRatio => previewSize!.width / previewSize!.height;

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

/// The currently locked capture orientation.
final DeviceOrientation lockedCaptureOrientation;
final DeviceOrientation? lockedCaptureOrientation;

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

/// The orientation of the currently running video recording.
final DeviceOrientation recordingOrientation;
final DeviceOrientation? recordingOrientation;

/// Creates a modified copy of the object.
///
/// Explicitly specified fields get the specified value, all other fields get
/// the same value of the current object.
CameraValue copyWith({
bool isInitialized,
bool isRecordingVideo,
bool isTakingPicture,
bool isStreamingImages,
String errorDescription,
Size previewSize,
bool isRecordingPaused,
FlashMode flashMode,
ExposureMode exposureMode,
FocusMode focusMode,
bool exposurePointSupported,
bool focusPointSupported,
DeviceOrientation deviceOrientation,
Optional<DeviceOrientation> lockedCaptureOrientation,
Optional<DeviceOrientation> recordingOrientation,
bool? isInitialized,
bool? isRecordingVideo,
bool? isTakingPicture,
bool? isStreamingImages,
String? errorDescription,
Size? previewSize,
bool? isRecordingPaused,
FlashMode? flashMode,
ExposureMode? exposureMode,
FocusMode? focusMode,
bool? exposurePointSupported,
bool? focusPointSupported,
DeviceOrientation? deviceOrientation,
Optional<DeviceOrientation>? lockedCaptureOrientation,
Optional<DeviceOrientation>? recordingOrientation,
}) {
return CameraValue(
isInitialized: isInitialized ?? this.isInitialized,
Expand Down Expand Up @@ -225,13 +227,17 @@ class CameraController extends ValueNotifier<CameraValue> {
/// The [ImageFormatGroup] describes the output of the raw image format.
///
/// When null the imageFormat will fallback to the platforms default.
final ImageFormatGroup imageFormatGroup;
final ImageFormatGroup? imageFormatGroup;

/// The id of a camera that hasn't been initialized.
@visibleForTesting
static const int kUninitializedCameraId = -1;
int _cameraId = kUninitializedCameraId;

int _cameraId;
bool _isDisposed = false;
StreamSubscription<dynamic> _imageStreamSubscription;
FutureOr<bool> _initCalled;
StreamSubscription _deviceOrientationSubscription;
StreamSubscription<dynamic>? _imageStreamSubscription;
FutureOr<bool>? _initCalled;
StreamSubscription? _deviceOrientationSubscription;

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

await CameraPlatform.instance.initializeCamera(
_cameraId,
imageFormatGroup: imageFormatGroup,
imageFormatGroup: imageFormatGroup ?? ImageFormatGroup.unknown,
);

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

await _imageStreamSubscription.cancel();
await _imageStreamSubscription?.cancel();
_imageStreamSubscription = null;
}

Expand Down Expand Up @@ -583,12 +589,16 @@ class CameraController extends ValueNotifier<CameraValue> {
}

/// Sets the exposure point for automatically determining the exposure value.
Future<void> setExposurePoint(Offset point) async {
///
/// Supplying a `null` value will reset the exposure point to it's default
/// value.
Future<void> setExposurePoint(Offset? point) async {
if (point != null &&
(point.dx < 0 || point.dx > 1 || point.dy < 0 || point.dy > 1)) {
throw ArgumentError(
'The values of point should be anywhere between (0,0) and (1,1).');
}

try {
await CameraPlatform.instance.setExposurePoint(
_cameraId,
Expand Down Expand Up @@ -682,7 +692,7 @@ class CameraController extends ValueNotifier<CameraValue> {
/// Locks the capture orientation.
///
/// If [orientation] is omitted, the current device orientation is used.
Future<void> lockCaptureOrientation([DeviceOrientation orientation]) async {
Future<void> lockCaptureOrientation([DeviceOrientation? orientation]) async {
try {
await CameraPlatform.instance.lockCaptureOrientation(
_cameraId, orientation ?? value.deviceOrientation);
Expand Down Expand Up @@ -715,7 +725,10 @@ class CameraController extends ValueNotifier<CameraValue> {
}

/// Sets the focus point for automatically determining the focus value.
Future<void> setFocusPoint(Offset point) async {
///
/// Supplying a `null` value will reset the focus point to it's default
/// value.
Future<void> setFocusPoint(Offset? point) async {
if (point != null &&
(point.dx < 0 || point.dx > 1 || point.dy < 0 || point.dy > 1)) {
throw ArgumentError(
Expand Down
6 changes: 3 additions & 3 deletions packages/camera/camera/lib/src/camera_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ class Plane {
/// The distance between adjacent pixel samples on Android, in bytes.
///
/// Will be `null` on iOS.
final int bytesPerPixel;
final int? bytesPerPixel;

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

/// Height of the pixel buffer on iOS.
///
/// Will be `null` on Android
final int height;
final int? height;

/// Width of the pixel buffer on iOS.
///
/// Will be `null` on Android.
final int width;
final int? width;
}

/// Describes how pixels are represented in an image.
Expand Down
6 changes: 3 additions & 3 deletions packages/camera/camera/lib/src/camera_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CameraPreview extends StatelessWidget {
final CameraController controller;

/// A widget to overlay on top of the camera preview
final Widget child;
final Widget? child;

@override
Widget build(BuildContext context) {
Expand All @@ -43,7 +43,7 @@ class CameraPreview extends StatelessWidget {

DeviceOrientation _getApplicableOrientation() {
return controller.value.isRecordingVideo
? controller.value.recordingOrientation
? controller.value.recordingOrientation!
: (controller.value.lockedCaptureOrientation ??
controller.value.deviceOrientation);
}
Expand All @@ -61,6 +61,6 @@ class CameraPreview extends StatelessWidget {
DeviceOrientation.portraitDown: 2,
DeviceOrientation.landscapeRight: 3,
};
return turns[_getApplicableOrientation()] + platformOffset;
return turns[_getApplicableOrientation()]! + platformOffset;
}
}
21 changes: 11 additions & 10 deletions packages/camera/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@ name: camera
description: A Flutter plugin for getting information about and controlling the
camera on Android and iOS. Supports previewing the camera feed, capturing images, capturing video,
and streaming image buffers to dart.
version: 0.7.0+4
version: 0.8.0-nullsafety
homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera

dependencies:
flutter:
sdk: flutter
camera_platform_interface: ^1.5.0
pedantic: ^1.8.0
quiver: ^2.1.5

camera_platform_interface: ^2.0.0-nullsafety

pedantic: ^1.10.0
quiver: ^3.0.0-nullsafety.3

dev_dependencies:
path_provider: ^0.5.0
video_player: ^0.10.0
video_player: ^2.0.0-nullsafety.7
flutter_test:
sdk: flutter
flutter_driver:
sdk: flutter
mockito: ^4.1.3
plugin_platform_interface: ^1.0.3
mockito: ^5.0.0-nullsafety.5
plugin_platform_interface: ^1.1.0-nullsafety.2

flutter:
plugin:
Expand All @@ -32,5 +33,5 @@ flutter:
pluginClass: CameraPlugin

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