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

Commit 08c9b40

Browse files
authored
Expand camera platform interface to support pausing the camera preview. (#4191)
1 parent d2f5c33 commit 08c9b40

6 files changed

Lines changed: 89 additions & 1 deletion

File tree

packages/camera/camera_platform_interface/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.1.0
2+
3+
* Introduces interface methods for pausing and resuming the camera preview.
4+
15
## 2.0.1
26

37
* Update platform_plugin_interface version requirement.

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,22 @@ class MethodChannelCamera extends CameraPlatform {
399399
}
400400
}
401401

402+
@override
403+
Future<void> pausePreview(int cameraId) async {
404+
await _channel.invokeMethod<double>(
405+
'pausePreview',
406+
<String, dynamic>{'cameraId': cameraId},
407+
);
408+
}
409+
410+
@override
411+
Future<void> resumePreview(int cameraId) async {
412+
await _channel.invokeMethod<double>(
413+
'resumePreview',
414+
<String, dynamic>{'cameraId': cameraId},
415+
);
416+
}
417+
402418
@override
403419
Widget buildPreview(int cameraId) {
404420
return Texture(textureId: cameraId);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@ abstract class CameraPlatform extends PlatformInterface {
235235
throw UnimplementedError('setZoomLevel() is not implemented.');
236236
}
237237

238+
/// Pause the active preview on the current frame for the selected camera.
239+
Future<void> pausePreview(int cameraId) {
240+
throw UnimplementedError('pausePreview() is not implemented.');
241+
}
242+
243+
/// Resume the paused preview for the selected camera.
244+
Future<void> resumePreview(int cameraId) {
245+
throw UnimplementedError('pausePreview() is not implemented.');
246+
}
247+
238248
/// Returns a widget showing a live camera preview.
239249
Widget buildPreview(int cameraId) {
240250
throw UnimplementedError('buildView() has not been implemented.');

packages/camera/camera_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/master/packages/camera/camer
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 2.0.1
7+
version: 2.1.0
88

99
environment:
1010
sdk: '>=2.12.0 <3.0.0'

packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,32 @@ void main() {
408408
throwsUnimplementedError,
409409
);
410410
});
411+
412+
test(
413+
'Default implementation of pausePreview() should throw unimplemented error',
414+
() {
415+
// Arrange
416+
final cameraPlatform = ExtendsCameraPlatform();
417+
418+
// Act & Assert
419+
expect(
420+
() => cameraPlatform.pausePreview(1),
421+
throwsUnimplementedError,
422+
);
423+
});
424+
425+
test(
426+
'Default implementation of resumePreview() should throw unimplemented error',
427+
() {
428+
// Arrange
429+
final cameraPlatform = ExtendsCameraPlatform();
430+
431+
// Act & Assert
432+
expect(
433+
() => cameraPlatform.resumePreview(1),
434+
throwsUnimplementedError,
435+
);
436+
});
411437
});
412438
}
413439

packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,38 @@ void main() {
923923
arguments: {'cameraId': cameraId}),
924924
]);
925925
});
926+
927+
test('Should pause the camera preview', () async {
928+
// Arrange
929+
MethodChannelMock channel = MethodChannelMock(
930+
channelName: 'plugins.flutter.io/camera',
931+
methods: {'pausePreview': null},
932+
);
933+
934+
// Act
935+
await camera.pausePreview(cameraId);
936+
937+
// Assert
938+
expect(channel.log, <Matcher>[
939+
isMethodCall('pausePreview', arguments: {'cameraId': cameraId}),
940+
]);
941+
});
942+
943+
test('Should resume the camera preview', () async {
944+
// Arrange
945+
MethodChannelMock channel = MethodChannelMock(
946+
channelName: 'plugins.flutter.io/camera',
947+
methods: {'resumePreview': null},
948+
);
949+
950+
// Act
951+
await camera.resumePreview(cameraId);
952+
953+
// Assert
954+
expect(channel.log, <Matcher>[
955+
isMethodCall('resumePreview', arguments: {'cameraId': cameraId}),
956+
]);
957+
});
926958
});
927959
});
928960
}

0 commit comments

Comments
 (0)