Skip to content

Commit 07cf89a

Browse files
authored
[camera] Ensure that channel.invokeMethod runs on the main thread (flutter#3444)
1 parent 31923c8 commit 07cf89a

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

packages/camera/camera/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.7.0+1
2+
3+
* Ensure communication from JAVA to Dart is done on the main UI thread.
4+
15
## 0.7.0
26

37
* BREAKING CHANGE: `CameraValue.aspectRatio` now returns `width / height` rather than `height / width`. [(commit)](https://github.com/flutter/plugins/commit/100c7470d4066b1d0f8f7e4ec6d7c943e736f970)

packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/DartMessenger.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
package io.flutter.plugins.camera;
66

7+
import android.os.Handler;
8+
import android.os.Looper;
79
import android.text.TextUtils;
810
import androidx.annotation.Nullable;
911
import io.flutter.embedding.engine.systemchannels.PlatformChannel;
@@ -104,7 +106,14 @@ void send(CameraEventType eventType, Map<String, Object> args) {
104106
if (cameraChannel == null) {
105107
return;
106108
}
107-
cameraChannel.invokeMethod(eventType.method, args);
109+
new Handler(Looper.getMainLooper())
110+
.post(
111+
new Runnable() {
112+
@Override
113+
public void run() {
114+
cameraChannel.invokeMethod(eventType.method, args);
115+
}
116+
});
108117
}
109118

110119
void send(DeviceEventType eventType) {
@@ -115,6 +124,13 @@ void send(DeviceEventType eventType, Map<String, Object> args) {
115124
if (deviceChannel == null) {
116125
return;
117126
}
118-
deviceChannel.invokeMethod(eventType.method, args);
127+
new Handler(Looper.getMainLooper())
128+
.post(
129+
new Runnable() {
130+
@Override
131+
public void run() {
132+
deviceChannel.invokeMethod(eventType.method, args);
133+
}
134+
});
119135
}
120136
}

packages/camera/camera/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: camera
22
description: A Flutter plugin for getting information about and controlling the
33
camera on Android and iOS. Supports previewing the camera feed, capturing images, capturing video,
44
and streaming image buffers to dart.
5-
version: 0.7.0
5+
version: 0.7.0+1
66
homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera
77

88
dependencies:

0 commit comments

Comments
 (0)