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

Commit 60a1137

Browse files
committed
Update platform interface to prevent breaking changes with current master
1 parent 930d901 commit 60a1137

File tree

6 files changed

+42
-38
lines changed

6 files changed

+42
-38
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,22 @@ class CameraInitializedEvent extends CameraEvent {
6969
CameraInitializedEvent(
7070
int cameraId,
7171
this.previewWidth,
72-
this.previewHeight,
72+
this.previewHeight, [
7373
this.exposureMode,
74+
this.exposurePointSupported = false,
7475
this.focusMode,
75-
this.exposurePointSupported,
76-
this.focusPointSupported,
77-
) : super(cameraId);
76+
this.focusPointSupported = false,
77+
]) : super(cameraId);
7878

7979
/// Converts the supplied [Map] to an instance of the [CameraInitializedEvent]
8080
/// class.
8181
CameraInitializedEvent.fromJson(Map<String, dynamic> json)
8282
: previewWidth = json['previewWidth'],
8383
previewHeight = json['previewHeight'],
8484
exposureMode = deserializeExposureMode(json['exposureMode']),
85+
exposurePointSupported = json['exposurePointSupported'] ?? false,
8586
focusMode = deserializeFocusMode(json['focusMode']),
86-
exposurePointSupported = json['exposurePointSupported'],
87-
focusPointSupported = json['focusPointSupported'],
87+
focusPointSupported = json['focusPointSupported'] ?? false,
8888
super(json['cameraId']);
8989

9090
/// Converts the [CameraInitializedEvent] instance into a [Map] instance that
@@ -94,8 +94,8 @@ class CameraInitializedEvent extends CameraEvent {
9494
'previewWidth': previewWidth,
9595
'previewHeight': previewHeight,
9696
'exposureMode': serializeExposureMode(exposureMode),
97-
'focusMode': serializeFocusMode(focusMode),
9897
'exposurePointSupported': exposurePointSupported,
98+
'focusMode': serializeFocusMode(focusMode),
9999
'focusPointSupported': focusPointSupported,
100100
};
101101

@@ -108,8 +108,8 @@ class CameraInitializedEvent extends CameraEvent {
108108
previewWidth == other.previewWidth &&
109109
previewHeight == other.previewHeight &&
110110
exposureMode == other.exposureMode &&
111-
focusMode == other.focusMode &&
112111
exposurePointSupported == other.exposurePointSupported &&
112+
focusMode == other.focusMode &&
113113
focusPointSupported == other.focusPointSupported;
114114

115115
@override
@@ -118,8 +118,8 @@ class CameraInitializedEvent extends CameraEvent {
118118
previewWidth.hashCode ^
119119
previewHeight.hashCode ^
120120
exposureMode.hashCode ^
121-
focusMode.hashCode ^
122121
exposurePointSupported.hashCode ^
122+
focusMode.hashCode ^
123123
focusPointSupported.hashCode;
124124
}
125125

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ class MethodChannelCamera extends CameraPlatform {
353353
call.arguments['previewWidth'],
354354
call.arguments['previewHeight'],
355355
deserializeExposureMode(call.arguments['exposureMode']),
356-
deserializeFocusMode(call.arguments['focusMode']),
357356
call.arguments['exposurePointSupported'],
357+
deserializeFocusMode(call.arguments['focusMode']),
358358
call.arguments['focusPointSupported'],
359359
));
360360
break;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ enum ExposureMode {
1313

1414
/// Returns the exposure mode as a String.
1515
String serializeExposureMode(ExposureMode exposureMode) {
16+
if (exposureMode == null) return null;
1617
switch (exposureMode) {
1718
case ExposureMode.locked:
1819
return 'locked';
@@ -25,6 +26,7 @@ String serializeExposureMode(ExposureMode exposureMode) {
2526

2627
/// Returns the exposure mode for a given String.
2728
ExposureMode deserializeExposureMode(String str) {
29+
if (str == null) return null;
2830
switch (str) {
2931
case "locked":
3032
return ExposureMode.locked;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ enum FocusMode {
1313

1414
/// Returns the focus mode as a String.
1515
String serializeFocusMode(FocusMode focusMode) {
16+
if (focusMode == null) return null;
1617
switch (focusMode) {
1718
case FocusMode.locked:
1819
return 'locked';
@@ -25,6 +26,7 @@ String serializeFocusMode(FocusMode focusMode) {
2526

2627
/// Returns the focus mode for a given String.
2728
FocusMode deserializeFocusMode(String str) {
29+
if (str == null) return null;
2830
switch (str) {
2931
case "locked":
3032
return FocusMode.locked;

packages/camera/camera_platform_interface/test/events/camera_event_test.dart

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void main() {
1313
group('CameraInitializedEvent tests', () {
1414
test('Constructor should initialize all properties', () {
1515
final event = CameraInitializedEvent(
16-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
16+
1, 1024, 640, ExposureMode.auto, true, FocusMode.auto, true);
1717

1818
expect(event.cameraId, 1);
1919
expect(event.previewWidth, 1024);
@@ -30,23 +30,23 @@ void main() {
3030
'previewWidth': 1024.0,
3131
'previewHeight': 640.0,
3232
'exposureMode': 'auto',
33-
'focusMode': 'auto',
3433
'exposurePointSupported': true,
34+
'focusMode': 'auto',
3535
'focusPointSupported': true
3636
});
3737

3838
expect(event.cameraId, 1);
3939
expect(event.previewWidth, 1024);
4040
expect(event.previewHeight, 640);
4141
expect(event.exposureMode, ExposureMode.auto);
42-
expect(event.focusMode, FocusMode.auto);
4342
expect(event.exposurePointSupported, true);
43+
expect(event.focusMode, FocusMode.auto);
4444
expect(event.focusPointSupported, true);
4545
});
4646

4747
test('toJson should return a map with all fields', () {
4848
final event = CameraInitializedEvent(
49-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
49+
1, 1024, 640, ExposureMode.auto, true, FocusMode.auto, true);
5050

5151
final jsonMap = event.toJson();
5252

@@ -55,93 +55,93 @@ void main() {
5555
expect(jsonMap['previewWidth'], 1024);
5656
expect(jsonMap['previewHeight'], 640);
5757
expect(jsonMap['exposureMode'], 'auto');
58-
expect(jsonMap['focusMode'], 'auto');
5958
expect(jsonMap['exposurePointSupported'], true);
59+
expect(jsonMap['focusMode'], 'auto');
6060
expect(jsonMap['focusPointSupported'], true);
6161
});
6262

6363
test('equals should return true if objects are the same', () {
6464
final firstEvent = CameraInitializedEvent(
65-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
65+
1, 1024, 640, ExposureMode.auto, true, FocusMode.auto, true);
6666
final secondEvent = CameraInitializedEvent(
67-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
67+
1, 1024, 640, ExposureMode.auto, true, FocusMode.auto, true);
6868

6969
expect(firstEvent == secondEvent, true);
7070
});
7171

7272
test('equals should return false if cameraId is different', () {
7373
final firstEvent = CameraInitializedEvent(
74-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
74+
1, 1024, 640, ExposureMode.auto, true, FocusMode.auto, true);
7575
final secondEvent = CameraInitializedEvent(
76-
2, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
76+
2, 1024, 640, ExposureMode.auto, true, FocusMode.auto, true);
7777

7878
expect(firstEvent == secondEvent, false);
7979
});
8080

8181
test('equals should return false if previewWidth is different', () {
8282
final firstEvent = CameraInitializedEvent(
83-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
83+
1, 1024, 640, ExposureMode.auto, true, FocusMode.auto, true);
8484
final secondEvent = CameraInitializedEvent(
85-
1, 2048, 640, ExposureMode.auto, FocusMode.auto, true, true);
85+
1, 2048, 640, ExposureMode.auto, true, FocusMode.auto, true);
8686

8787
expect(firstEvent == secondEvent, false);
8888
});
8989

9090
test('equals should return false if previewHeight is different', () {
9191
final firstEvent = CameraInitializedEvent(
92-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
92+
1, 1024, 640, ExposureMode.auto, true, FocusMode.auto, true);
9393
final secondEvent = CameraInitializedEvent(
94-
1, 1024, 980, ExposureMode.auto, FocusMode.auto, true, true);
94+
1, 1024, 980, ExposureMode.auto, true, FocusMode.auto, true);
9595

9696
expect(firstEvent == secondEvent, false);
9797
});
9898

9999
test('equals should return false if exposureMode is different', () {
100100
final firstEvent = CameraInitializedEvent(
101-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
101+
1, 1024, 640, ExposureMode.auto, true, FocusMode.auto, true);
102102
final secondEvent = CameraInitializedEvent(
103-
1, 1024, 640, ExposureMode.locked, FocusMode.auto, true, true);
103+
1, 1024, 640, ExposureMode.locked, true, FocusMode.auto, true);
104104

105105
expect(firstEvent == secondEvent, false);
106106
});
107107

108108
test('equals should return false if exposurePointSupported is different',
109109
() {
110110
final firstEvent = CameraInitializedEvent(
111-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
111+
1, 1024, 640, ExposureMode.auto, true, FocusMode.auto, true);
112112
final secondEvent = CameraInitializedEvent(
113-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, false, true);
113+
1, 1024, 640, ExposureMode.auto, false, FocusMode.auto, true);
114114

115115
expect(firstEvent == secondEvent, false);
116116
});
117117

118118
test('equals should return false if focusMode is different', () {
119119
final firstEvent = CameraInitializedEvent(
120-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
120+
1, 1024, 640, ExposureMode.auto, true, FocusMode.auto, true);
121121
final secondEvent = CameraInitializedEvent(
122-
1, 1024, 640, ExposureMode.auto, FocusMode.locked, true, true);
122+
1, 1024, 640, ExposureMode.auto, true, FocusMode.locked, true);
123123

124124
expect(firstEvent == secondEvent, false);
125125
});
126126

127127
test('equals should return false if focusPointSupported is different', () {
128128
final firstEvent = CameraInitializedEvent(
129-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
129+
1, 1024, 640, ExposureMode.auto, true, FocusMode.auto, true);
130130
final secondEvent = CameraInitializedEvent(
131-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, false);
131+
1, 1024, 640, ExposureMode.auto, true, FocusMode.auto, false);
132132

133133
expect(firstEvent == secondEvent, false);
134134
});
135135

136136
test('hashCode should match hashCode of all properties', () {
137137
final event = CameraInitializedEvent(
138-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
138+
1, 1024, 640, ExposureMode.auto, true, FocusMode.auto, true);
139139
final expectedHashCode = event.cameraId.hashCode ^
140140
event.previewWidth.hashCode ^
141141
event.previewHeight.hashCode ^
142142
event.exposureMode.hashCode ^
143-
event.focusMode.hashCode ^
144143
event.exposurePointSupported.hashCode ^
144+
event.focusMode.hashCode ^
145145
event.focusPointSupported.hashCode;
146146

147147
expect(event.hashCode, expectedHashCode);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ void main() {
125125
1920,
126126
1080,
127127
ExposureMode.auto,
128-
FocusMode.auto,
129128
true,
129+
FocusMode.auto,
130130
true,
131131
));
132132
await initializeFuture;
@@ -165,8 +165,8 @@ void main() {
165165
1920,
166166
1080,
167167
ExposureMode.auto,
168-
FocusMode.auto,
169168
true,
169+
FocusMode.auto,
170170
true,
171171
));
172172
await initializeFuture;
@@ -209,8 +209,8 @@ void main() {
209209
1920,
210210
1080,
211211
ExposureMode.auto,
212-
FocusMode.auto,
213212
true,
213+
FocusMode.auto,
214214
true,
215215
));
216216
await initializeFuture;
@@ -228,8 +228,8 @@ void main() {
228228
3840,
229229
2160,
230230
ExposureMode.auto,
231-
FocusMode.auto,
232231
true,
232+
FocusMode.auto,
233233
true,
234234
);
235235
await camera.handleMethodCall(
@@ -341,8 +341,8 @@ void main() {
341341
1920,
342342
1080,
343343
ExposureMode.auto,
344-
FocusMode.auto,
345344
true,
345+
FocusMode.auto,
346346
true,
347347
),
348348
);

0 commit comments

Comments
 (0)