Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/camera/camera_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.0

* Introduces interface methods for pausing and resuming the camera preview.

## 2.0.1

* Update platform_plugin_interface version requirement.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,22 @@ class MethodChannelCamera extends CameraPlatform {
}
}

@override
Future<void> pausePreview(int cameraId) async {
await _channel.invokeMethod<double>(
'pausePreview',
<String, dynamic>{'cameraId': cameraId},
);
}

@override
Future<void> resumePreview(int cameraId) async {
await _channel.invokeMethod<double>(
'resumePreview',
<String, dynamic>{'cameraId': cameraId},
);
}

@override
Widget buildPreview(int cameraId) {
return Texture(textureId: cameraId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ abstract class CameraPlatform extends PlatformInterface {
throw UnimplementedError('setZoomLevel() is not implemented.');
}

/// Pause the active preview on the current frame for the selected camera.
Future<void> pausePreview(int cameraId) {
throw UnimplementedError('pausePreview() is not implemented.');
}

/// Resume the paused preview for the selected camera.
Future<void> resumePreview(int cameraId) {
throw UnimplementedError('pausePreview() is not implemented.');
}

/// Returns a widget showing a live camera preview.
Widget buildPreview(int cameraId) {
throw UnimplementedError('buildView() has not been implemented.');
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/master/packages/camera/camer
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.0.1
version: 2.1.0

environment:
sdk: '>=2.12.0 <3.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,32 @@ void main() {
throwsUnimplementedError,
);
});

test(
'Default implementation of pausePreview() should throw unimplemented error',
() {
// Arrange
final cameraPlatform = ExtendsCameraPlatform();

// Act & Assert
expect(
() => cameraPlatform.pausePreview(1),
throwsUnimplementedError,
);
});

test(
'Default implementation of resumePreview() should throw unimplemented error',
() {
// Arrange
final cameraPlatform = ExtendsCameraPlatform();

// Act & Assert
expect(
() => cameraPlatform.resumePreview(1),
throwsUnimplementedError,
);
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,38 @@ void main() {
arguments: {'cameraId': cameraId}),
]);
});

test('Should pause the camera preview', () async {
// Arrange
MethodChannelMock channel = MethodChannelMock(
channelName: 'plugins.flutter.io/camera',
methods: {'pausePreview': null},
);

// Act
await camera.pausePreview(cameraId);

// Assert
expect(channel.log, <Matcher>[
isMethodCall('pausePreview', arguments: {'cameraId': cameraId}),
]);
});

test('Should resume the camera preview', () async {
// Arrange
MethodChannelMock channel = MethodChannelMock(
channelName: 'plugins.flutter.io/camera',
methods: {'resumePreview': null},
);

// Act
await camera.resumePreview(cameraId);

// Assert
expect(channel.log, <Matcher>[
isMethodCall('resumePreview', arguments: {'cameraId': cameraId}),
]);
});
});
});
}