You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
final channel =MethodChannel('flutter.io/cameraPlugin/camera$cameraId');
104
110
channel.setMethodCallHandler(
@@ -125,15 +131,16 @@ class MethodChannelCamera extends CameraPlatform {
125
131
126
132
@override
127
133
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
+
128
140
await _channel.invokeMethod<void>(
129
141
'dispose',
130
142
<String, dynamic>{'cameraId': cameraId},
131
143
);
132
-
133
-
if (_channels.containsKey(cameraId)) {
134
-
_channels[cameraId].setMethodCallHandler(null);
135
-
_channels.remove(cameraId);
136
-
}
137
144
}
138
145
139
146
@override
@@ -169,7 +176,9 @@ class MethodChannelCamera extends CameraPlatform {
169
176
170
177
@override
171
178
Future<void> lockCaptureOrientation(
172
-
int cameraId, DeviceOrientation orientation) async {
179
+
int cameraId,
180
+
DeviceOrientation orientation,
181
+
) async {
173
182
await _channel.invokeMethod<String>(
174
183
'lockCaptureOrientation',
175
184
<String, dynamic>{
@@ -189,10 +198,18 @@ class MethodChannelCamera extends CameraPlatform {
189
198
190
199
@override
191
200
Future<XFile> takePicture(int cameraId) async {
192
-
String path =await _channel.invokeMethod<String>(
201
+
final path =await _channel.invokeMethod<String>(
193
202
'takePicture',
194
203
<String, dynamic>{'cameraId': cameraId},
195
204
);
205
+
206
+
if (path ==null) {
207
+
throwCameraException(
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
+
196
213
returnXFile(path);
197
214
}
198
215
@@ -202,7 +219,7 @@ class MethodChannelCamera extends CameraPlatform {
202
219
203
220
@override
204
221
Future<void> startVideoRecording(int cameraId,
205
-
{Duration maxVideoDuration}) async {
222
+
{Duration? maxVideoDuration}) async {
206
223
await _channel.invokeMethod<void>(
207
224
'startVideoRecording',
208
225
<String, dynamic>{
@@ -214,10 +231,18 @@ class MethodChannelCamera extends CameraPlatform {
'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
+
221
246
returnXFile(path);
222
247
}
223
248
@@ -255,9 +280,10 @@ class MethodChannelCamera extends CameraPlatform {
0 commit comments