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

Commit abfb158

Browse files
committed
Split CameraEvents into separate streams
1 parent 96b40fc commit abfb158

File tree

6 files changed

+45
-132
lines changed

6 files changed

+45
-132
lines changed

packages/camera/camera_platform_interface/lib/camera_platform_interface.dart

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
export 'src/events/camera_event.dart';
56
export 'src/platform_interface/camera_platform.dart';
67
export 'src/types/types.dart';

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

+24-24
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'dart:async';
66

7+
import 'package:flutter/widgets.dart';
78
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
89
import 'package:camera_platform_interface/src/method_channel/method_channel_camera.dart';
910

@@ -41,7 +42,7 @@ abstract class CameraPlatform extends PlatformInterface {
4142
throw UnimplementedError('availableCameras() is not implemented.');
4243
}
4344

44-
/// Initializes the camera on the device and returns its textureId.
45+
/// Initializes the camera on the device and returns its cameraId.
4546
Future<int> initializeCamera(
4647
CameraDescription cameraDescription, {
4748
ResolutionPreset resolutionPreset,
@@ -50,13 +51,23 @@ abstract class CameraPlatform extends PlatformInterface {
5051
throw UnimplementedError('initializeCamera() is not implemented.');
5152
}
5253

53-
/// Returns a Stream of [CameraEvent]s.
54-
Stream<CameraEvent> cameraEventsFor(int textureId) {
55-
throw UnimplementedError('videoEventsFor() has not been implemented.');
54+
/// The camera's resolution has changed
55+
Stream<ResolutionChangedEvent> onResolutionChanged(int cameraId) {
56+
throw UnimplementedError('onResolutionChanged() is not implemented.');
57+
}
58+
59+
/// The camera started to close.
60+
Stream<CameraClosingEvent> onCameraClosing(int cameraId) {
61+
throw UnimplementedError('onCameraClosing() is not implemented.');
62+
}
63+
64+
/// The camera experienced an error.
65+
Stream<CameraErrorEvent> onCameraError(int cameraId) {
66+
throw UnimplementedError('onCameraError() is not implemented.');
5667
}
5768

5869
/// Captures an image and saves it to [path].
59-
Future<void> takePicture(int textureId, String path) {
70+
Future<void> takePicture(int cameraId, String path) {
6071
throw UnimplementedError('takePicture() is not implemented.');
6172
}
6273

@@ -73,43 +84,32 @@ abstract class CameraPlatform extends PlatformInterface {
7384
/// The file is written on the flight as the video is being recorded.
7485
/// If a file already exists at the provided path an error will be thrown.
7586
/// The file can be read as soon as [stopVideoRecording] returns.
76-
Future<void> startVideoRecording(int textureId, String path) {
87+
Future<void> startVideoRecording(int cameraId, String path) {
7788
throw UnimplementedError('startVideoRecording() is not implemented.');
7889
}
7990

8091
/// Stop the video recording.
81-
Future<void> stopVideoRecording(int textureId) {
92+
Future<void> stopVideoRecording(int cameraId) {
8293
throw UnimplementedError('stopVideoRecording() is not implemented.');
8394
}
8495

8596
/// Pause video recording.
86-
Future<void> pauseVideoRecording(int textureId) {
97+
Future<void> pauseVideoRecording(int cameraId) {
8798
throw UnimplementedError('pauseVideoRecording() is not implemented.');
8899
}
89100

90101
/// Resume video recording after pausing.
91-
Future<void> resumeVideoRecording(int textureId) {
102+
Future<void> resumeVideoRecording(int cameraId) {
92103
throw UnimplementedError('resumeVideoRecording() is not implemented.');
93104
}
94105

95-
/// Start streaming images from platform camera.
96-
///
97-
/// When running continuously with [CameraPreview] widget, this function runs
98-
/// best with [ResolutionPreset.low]. Running on [ResolutionPreset.high] can
99-
/// have significant frame rate drops for [CameraPreview] on lower end
100-
/// devices.
101-
// TODO(bmparr): Add settings for resolution and fps.
102-
Future<void> startImageStream(ImageAvailableHandler onAvailable) {
103-
throw UnimplementedError('startImageStream() is not implemented.');
104-
}
105-
106-
/// Stop streaming images from platform camera.
107-
Future<void> stopImageStream() {
108-
throw UnimplementedError('stopImageStream() is not implemented.');
106+
/// Returns a widget showing a live camera preview.
107+
Widget buildView(int cameraId) {
108+
throw UnimplementedError('buildView() has not been implemented.');
109109
}
110110

111111
/// Releases the resources of this camera.
112-
Future<void> dispose(int textureId) {
112+
Future<void> dispose(int cameraId) {
113113
throw UnimplementedError('dispose() is not implemented.');
114114
}
115115
}

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

-11
This file was deleted.

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

-76
This file was deleted.

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

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
export 'callbacks.dart';
65
export 'camera_description.dart';
7-
export 'camera_event.dart';
86
export 'camera_image.dart';
97
export 'resolution_preset.dart';

packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart

+20-19
Original file line numberDiff line numberDiff line change
@@ -45,117 +45,118 @@ void main() {
4545
});
4646

4747
test(
48-
'Default implementation of cameraEventsFor() should throw unimplemented error',
48+
'Default implementation of onResolutionChanged() should throw unimplemented error',
4949
() {
5050
// Arrange
5151
final cameraPlatform = ExtendsCameraPlatform();
5252

5353
// Act & Assert
5454
expect(
55-
() => cameraPlatform.cameraEventsFor(1),
55+
() => cameraPlatform.onResolutionChanged(1),
5656
throwsUnimplementedError,
5757
);
5858
});
5959

60-
test('Default implementation of dispose() should throw unimplemented error',
60+
61+
test(
62+
'Default implementation of onCameraClosing() should throw unimplemented error',
6163
() {
6264
// Arrange
6365
final cameraPlatform = ExtendsCameraPlatform();
6466

6567
// Act & Assert
6668
expect(
67-
() => cameraPlatform.dispose(1),
69+
() => cameraPlatform.onCameraClosing(1),
6870
throwsUnimplementedError,
6971
);
7072
});
7173

7274
test(
73-
'Default implementation of initialize() should throw unimplemented error',
75+
'Default implementation of onCameraError() should throw unimplemented error',
7476
() {
7577
// Arrange
7678
final cameraPlatform = ExtendsCameraPlatform();
7779

7880
// Act & Assert
7981
expect(
80-
() => cameraPlatform.initializeCamera(null),
82+
() => cameraPlatform.onCameraError(1),
8183
throwsUnimplementedError,
8284
);
8385
});
8486

85-
test(
86-
'Default implementation of pauseVideoRecording() should throw unimplemented error',
87+
test('Default implementation of dispose() should throw unimplemented error',
8788
() {
8889
// Arrange
8990
final cameraPlatform = ExtendsCameraPlatform();
9091

9192
// Act & Assert
9293
expect(
93-
() => cameraPlatform.pauseVideoRecording(1),
94+
() => cameraPlatform.dispose(1),
9495
throwsUnimplementedError,
9596
);
9697
});
9798

9899
test(
99-
'Default implementation of prepareForVideoRecording() should throw unimplemented error',
100+
'Default implementation of initialize() should throw unimplemented error',
100101
() {
101102
// Arrange
102103
final cameraPlatform = ExtendsCameraPlatform();
103104

104105
// Act & Assert
105106
expect(
106-
() => cameraPlatform.prepareForVideoRecording(),
107+
() => cameraPlatform.initializeCamera(null),
107108
throwsUnimplementedError,
108109
);
109110
});
110111

111112
test(
112-
'Default implementation of resumeVideoRecording() should throw unimplemented error',
113+
'Default implementation of pauseVideoRecording() should throw unimplemented error',
113114
() {
114115
// Arrange
115116
final cameraPlatform = ExtendsCameraPlatform();
116117

117118
// Act & Assert
118119
expect(
119-
() => cameraPlatform.resumeVideoRecording(1),
120+
() => cameraPlatform.pauseVideoRecording(1),
120121
throwsUnimplementedError,
121122
);
122123
});
123124

124125
test(
125-
'Default implementation of startImageStream() should throw unimplemented error',
126+
'Default implementation of prepareForVideoRecording() should throw unimplemented error',
126127
() {
127128
// Arrange
128129
final cameraPlatform = ExtendsCameraPlatform();
129130

130131
// Act & Assert
131132
expect(
132-
() => cameraPlatform.startImageStream(null),
133+
() => cameraPlatform.prepareForVideoRecording(),
133134
throwsUnimplementedError,
134135
);
135136
});
136137

137138
test(
138-
'Default implementation of startVideoRecording() should throw unimplemented error',
139+
'Default implementation of resumeVideoRecording() should throw unimplemented error',
139140
() {
140141
// Arrange
141142
final cameraPlatform = ExtendsCameraPlatform();
142143

143144
// Act & Assert
144145
expect(
145-
() => cameraPlatform.startVideoRecording(1, null),
146+
() => cameraPlatform.resumeVideoRecording(1),
146147
throwsUnimplementedError,
147148
);
148149
});
149150

150151
test(
151-
'Default implementation of stopImageStream() should throw unimplemented error',
152+
'Default implementation of startVideoRecording() should throw unimplemented error',
152153
() {
153154
// Arrange
154155
final cameraPlatform = ExtendsCameraPlatform();
155156

156157
// Act & Assert
157158
expect(
158-
() => cameraPlatform.stopImageStream(),
159+
() => cameraPlatform.startVideoRecording(1, null),
159160
throwsUnimplementedError,
160161
);
161162
});

0 commit comments

Comments
 (0)