Skip to content

Commit 8063e86

Browse files
committed
Revert "[camera_platform_interface] Migrate to null safety (flutter#3497)"
This reverts commit 545c97f.
1 parent bb21db8 commit 8063e86

File tree

13 files changed

+108
-205
lines changed

13 files changed

+108
-205
lines changed

packages/camera/camera_platform_interface/CHANGELOG.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
## 2.0.0-nullsafety
2-
3-
- Migrate to null safety.
4-
51
## 1.6.0
62

73
- Added VideoRecordedEvent to support ending a video recording in the native implementation.

packages/camera/camera_platform_interface/lib/src/events/camera_event.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ class CameraInitializedEvent extends CameraEvent {
7070
CameraInitializedEvent(
7171
int cameraId,
7272
this.previewWidth,
73-
this.previewHeight,
73+
this.previewHeight, [
7474
this.exposureMode,
75-
this.exposurePointSupported,
75+
this.exposurePointSupported = false,
7676
this.focusMode,
77-
this.focusPointSupported,
78-
) : super(cameraId);
77+
this.focusPointSupported = false,
78+
]) : super(cameraId);
7979

8080
/// Converts the supplied [Map] to an instance of the [CameraInitializedEvent]
8181
/// class.
@@ -242,7 +242,7 @@ class VideoRecordedEvent extends CameraEvent {
242242
final XFile file;
243243

244244
/// Maximum duration of the recorded video.
245-
final Duration? maxVideoDuration;
245+
final Duration maxVideoDuration;
246246

247247
/// Build a VideoRecordedEvent triggered from the camera with the `cameraId`.
248248
///

packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart

Lines changed: 59 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import 'package:camera_platform_interface/src/types/focus_mode.dart';
1111
import 'package:camera_platform_interface/src/types/image_format_group.dart';
1212
import 'package:camera_platform_interface/src/utils/utils.dart';
1313
import 'package:cross_file/cross_file.dart';
14-
import 'package:flutter/foundation.dart';
1514
import 'package:flutter/services.dart';
1615
import 'package:flutter/widgets.dart';
1716
import 'package:meta/meta.dart';
@@ -59,13 +58,8 @@ class MethodChannelCamera extends CameraPlatform {
5958
@override
6059
Future<List<CameraDescription>> availableCameras() async {
6160
try {
62-
final cameras = await _channel
61+
final List<Map<dynamic, dynamic>> cameras = await _channel
6362
.invokeListMethod<Map<dynamic, dynamic>>('availableCameras');
64-
65-
if (cameras == null) {
66-
return <CameraDescription>[];
67-
}
68-
6963
return cameras.map((Map<dynamic, dynamic> camera) {
7064
return CameraDescription(
7165
name: camera['name'],
@@ -81,30 +75,30 @@ class MethodChannelCamera extends CameraPlatform {
8175
@override
8276
Future<int> createCamera(
8377
CameraDescription cameraDescription,
84-
ResolutionPreset? resolutionPreset, {
85-
bool enableAudio = true,
78+
ResolutionPreset resolutionPreset, {
79+
bool enableAudio,
8680
}) async {
8781
try {
88-
final reply = await _channel
89-
.invokeMapMethod<String, dynamic>('create', <String, dynamic>{
90-
'cameraName': cameraDescription.name,
91-
'resolutionPreset': resolutionPreset != null
92-
? _serializeResolutionPreset(resolutionPreset)
93-
: null,
94-
'enableAudio': enableAudio,
95-
});
96-
97-
return reply!['cameraId'];
82+
final Map<String, dynamic> reply =
83+
await _channel.invokeMapMethod<String, dynamic>(
84+
'create',
85+
<String, dynamic>{
86+
'cameraName': cameraDescription.name,
87+
'resolutionPreset': resolutionPreset != null
88+
? _serializeResolutionPreset(resolutionPreset)
89+
: null,
90+
'enableAudio': enableAudio,
91+
},
92+
);
93+
return reply['cameraId'];
9894
} on PlatformException catch (e) {
9995
throw CameraException(e.code, e.message);
10096
}
10197
}
10298

10399
@override
104-
Future<void> initializeCamera(
105-
int cameraId, {
106-
ImageFormatGroup imageFormatGroup = ImageFormatGroup.unknown,
107-
}) {
100+
Future<void> initializeCamera(int cameraId,
101+
{ImageFormatGroup imageFormatGroup}) {
108102
_channels.putIfAbsent(cameraId, () {
109103
final channel = MethodChannel('flutter.io/cameraPlugin/camera$cameraId');
110104
channel.setMethodCallHandler(
@@ -131,16 +125,15 @@ class MethodChannelCamera extends CameraPlatform {
131125

132126
@override
133127
Future<void> dispose(int cameraId) async {
134-
if (_channels.containsKey(cameraId)) {
135-
final cameraChannel = _channels[cameraId];
136-
cameraChannel?.setMethodCallHandler(null);
137-
_channels.remove(cameraId);
138-
}
139-
140128
await _channel.invokeMethod<void>(
141129
'dispose',
142130
<String, dynamic>{'cameraId': cameraId},
143131
);
132+
133+
if (_channels.containsKey(cameraId)) {
134+
_channels[cameraId].setMethodCallHandler(null);
135+
_channels.remove(cameraId);
136+
}
144137
}
145138

146139
@override
@@ -176,9 +169,7 @@ class MethodChannelCamera extends CameraPlatform {
176169

177170
@override
178171
Future<void> lockCaptureOrientation(
179-
int cameraId,
180-
DeviceOrientation orientation,
181-
) async {
172+
int cameraId, DeviceOrientation orientation) async {
182173
await _channel.invokeMethod<String>(
183174
'lockCaptureOrientation',
184175
<String, dynamic>{
@@ -198,18 +189,10 @@ class MethodChannelCamera extends CameraPlatform {
198189

199190
@override
200191
Future<XFile> takePicture(int cameraId) async {
201-
final path = await _channel.invokeMethod<String>(
192+
String path = await _channel.invokeMethod<String>(
202193
'takePicture',
203194
<String, dynamic>{'cameraId': cameraId},
204195
);
205-
206-
if (path == null) {
207-
throw CameraException(
208-
'INVALID_PATH',
209-
'The platform "$defaultTargetPlatform" did not return a path while reporting success. The platform should always return a valid path or report an error.',
210-
);
211-
}
212-
213196
return XFile(path);
214197
}
215198

@@ -219,7 +202,7 @@ class MethodChannelCamera extends CameraPlatform {
219202

220203
@override
221204
Future<void> startVideoRecording(int cameraId,
222-
{Duration? maxVideoDuration}) async {
205+
{Duration maxVideoDuration}) async {
223206
await _channel.invokeMethod<void>(
224207
'startVideoRecording',
225208
<String, dynamic>{
@@ -231,18 +214,10 @@ class MethodChannelCamera extends CameraPlatform {
231214

232215
@override
233216
Future<XFile> stopVideoRecording(int cameraId) async {
234-
final path = await _channel.invokeMethod<String>(
217+
String path = await _channel.invokeMethod<String>(
235218
'stopVideoRecording',
236219
<String, dynamic>{'cameraId': cameraId},
237220
);
238-
239-
if (path == null) {
240-
throw CameraException(
241-
'INVALID_PATH',
242-
'The platform "$defaultTargetPlatform" did not return a path while reporting success. The platform should always return a valid path or report an error.',
243-
);
244-
}
245-
246221
return XFile(path);
247222
}
248223

@@ -280,10 +255,9 @@ class MethodChannelCamera extends CameraPlatform {
280255
);
281256

282257
@override
283-
Future<void> setExposurePoint(int cameraId, Point<double>? point) {
258+
Future<void> setExposurePoint(int cameraId, Point<double> point) {
284259
assert(point == null || point.x >= 0 && point.x <= 1);
285260
assert(point == null || point.y >= 0 && point.y <= 1);
286-
287261
return _channel.invokeMethod<void>(
288262
'setExposurePoint',
289263
<String, dynamic>{
@@ -296,47 +270,35 @@ class MethodChannelCamera extends CameraPlatform {
296270
}
297271

298272
@override
299-
Future<double> getMinExposureOffset(int cameraId) async {
300-
final minExposureOffset = await _channel.invokeMethod<double>(
301-
'getMinExposureOffset',
302-
<String, dynamic>{'cameraId': cameraId},
303-
);
304-
305-
return minExposureOffset!;
306-
}
273+
Future<double> getMinExposureOffset(int cameraId) =>
274+
_channel.invokeMethod<double>(
275+
'getMinExposureOffset',
276+
<String, dynamic>{'cameraId': cameraId},
277+
);
307278

308279
@override
309-
Future<double> getMaxExposureOffset(int cameraId) async {
310-
final maxExposureOffset = await _channel.invokeMethod<double>(
311-
'getMaxExposureOffset',
312-
<String, dynamic>{'cameraId': cameraId},
313-
);
314-
315-
return maxExposureOffset!;
316-
}
280+
Future<double> getMaxExposureOffset(int cameraId) =>
281+
_channel.invokeMethod<double>(
282+
'getMaxExposureOffset',
283+
<String, dynamic>{'cameraId': cameraId},
284+
);
317285

318286
@override
319-
Future<double> getExposureOffsetStepSize(int cameraId) async {
320-
final stepSize = await _channel.invokeMethod<double>(
321-
'getExposureOffsetStepSize',
322-
<String, dynamic>{'cameraId': cameraId},
323-
);
324-
325-
return stepSize!;
326-
}
287+
Future<double> getExposureOffsetStepSize(int cameraId) =>
288+
_channel.invokeMethod<double>(
289+
'getExposureOffsetStepSize',
290+
<String, dynamic>{'cameraId': cameraId},
291+
);
327292

328293
@override
329-
Future<double> setExposureOffset(int cameraId, double offset) async {
330-
final appliedOffset = await _channel.invokeMethod<double>(
331-
'setExposureOffset',
332-
<String, dynamic>{
333-
'cameraId': cameraId,
334-
'offset': offset,
335-
},
336-
);
337-
338-
return appliedOffset!;
339-
}
294+
Future<double> setExposureOffset(int cameraId, double offset) =>
295+
_channel.invokeMethod<double>(
296+
'setExposureOffset',
297+
<String, dynamic>{
298+
'cameraId': cameraId,
299+
'offset': offset,
300+
},
301+
);
340302

341303
@override
342304
Future<void> setFocusMode(int cameraId, FocusMode mode) =>
@@ -349,10 +311,9 @@ class MethodChannelCamera extends CameraPlatform {
349311
);
350312

351313
@override
352-
Future<void> setFocusPoint(int cameraId, Point<double>? point) {
314+
Future<void> setFocusPoint(int cameraId, Point<double> point) {
353315
assert(point == null || point.x >= 0 && point.x <= 1);
354316
assert(point == null || point.y >= 0 && point.y <= 1);
355-
356317
return _channel.invokeMethod<void>(
357318
'setFocusPoint',
358319
<String, dynamic>{
@@ -365,24 +326,16 @@ class MethodChannelCamera extends CameraPlatform {
365326
}
366327

367328
@override
368-
Future<double> getMaxZoomLevel(int cameraId) async {
369-
final maxZoomLevel = await _channel.invokeMethod<double>(
370-
'getMaxZoomLevel',
371-
<String, dynamic>{'cameraId': cameraId},
372-
);
373-
374-
return maxZoomLevel!;
375-
}
329+
Future<double> getMaxZoomLevel(int cameraId) => _channel.invokeMethod<double>(
330+
'getMaxZoomLevel',
331+
<String, dynamic>{'cameraId': cameraId},
332+
);
376333

377334
@override
378-
Future<double> getMinZoomLevel(int cameraId) async {
379-
final minZoomLevel = await _channel.invokeMethod<double>(
380-
'getMinZoomLevel',
381-
<String, dynamic>{'cameraId': cameraId},
382-
);
383-
384-
return minZoomLevel!;
385-
}
335+
Future<double> getMinZoomLevel(int cameraId) => _channel.invokeMethod<double>(
336+
'getMinZoomLevel',
337+
<String, dynamic>{'cameraId': cameraId},
338+
);
386339

387340
@override
388341
Future<void> setZoomLevel(int cameraId, double zoom) async {

packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ abstract class CameraPlatform extends PlatformInterface {
5151
/// Creates an uninitialized camera instance and returns the cameraId.
5252
Future<int> createCamera(
5353
CameraDescription cameraDescription,
54-
ResolutionPreset? resolutionPreset, {
55-
bool enableAudio = true,
54+
ResolutionPreset resolutionPreset, {
55+
bool enableAudio,
5656
}) {
5757
throw UnimplementedError('createCamera() is not implemented.');
5858
}
@@ -62,10 +62,8 @@ abstract class CameraPlatform extends PlatformInterface {
6262
/// [imageFormatGroup] is used to specify the image formatting used.
6363
/// On Android this defaults to ImageFormat.YUV_420_888 and applies only to the imageStream.
6464
/// On iOS this defaults to kCVPixelFormatType_32BGRA.
65-
Future<void> initializeCamera(
66-
int cameraId, {
67-
ImageFormatGroup imageFormatGroup = ImageFormatGroup.unknown,
68-
}) {
65+
Future<void> initializeCamera(int cameraId,
66+
{ImageFormatGroup imageFormatGroup}) {
6967
throw UnimplementedError('initializeCamera() is not implemented.');
7068
}
7169

@@ -132,7 +130,7 @@ abstract class CameraPlatform extends PlatformInterface {
132130
/// meaning the recording will continue until manually stopped.
133131
/// With [maxVideoDuration] set the video is returned in a [VideoRecordedEvent]
134132
/// through the [onVideoRecordedEvent] stream when the set duration is reached.
135-
Future<void> startVideoRecording(int cameraId, {Duration? maxVideoDuration}) {
133+
Future<void> startVideoRecording(int cameraId, {Duration maxVideoDuration}) {
136134
throw UnimplementedError('startVideoRecording() is not implemented.');
137135
}
138136

@@ -162,10 +160,7 @@ abstract class CameraPlatform extends PlatformInterface {
162160
}
163161

164162
/// Sets the exposure point for automatically determining the exposure values.
165-
///
166-
/// Supplying `null` for the [point] argument will result in resetting to the
167-
/// original exposure point value.
168-
Future<void> setExposurePoint(int cameraId, Point<double>? point) {
163+
Future<void> setExposurePoint(int cameraId, Point<double> point) {
169164
throw UnimplementedError('setExposurePoint() is not implemented.');
170165
}
171166

@@ -207,10 +202,7 @@ abstract class CameraPlatform extends PlatformInterface {
207202
}
208203

209204
/// Sets the focus point for automatically determining the focus values.
210-
///
211-
/// Supplying `null` for the [point] argument will result in resetting to the
212-
/// original focus point value.
213-
Future<void> setFocusPoint(int cameraId, Point<double>? point) {
205+
Future<void> setFocusPoint(int cameraId, Point<double> point) {
214206
throw UnimplementedError('setFocusPoint() is not implemented.');
215207
}
216208

packages/camera/camera_platform_interface/lib/src/types/camera_description.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ enum CameraLensDirection {
1717
/// Properties of a camera device.
1818
class CameraDescription {
1919
/// Creates a new camera description with the given properties.
20-
CameraDescription({
21-
required this.name,
22-
required this.lensDirection,
23-
required this.sensorOrientation,
24-
});
20+
CameraDescription({this.name, this.lensDirection, this.sensorOrientation});
2521

2622
/// The name of the camera device.
2723
final String name;

packages/camera/camera_platform_interface/lib/src/types/camera_exception.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CameraException implements Exception {
1313
String code;
1414

1515
/// Textual description of the error.
16-
String? description;
16+
String description;
1717

1818
@override
1919
String toString() => 'CameraException($code, $description)';

0 commit comments

Comments
 (0)