Skip to content

Commit

Permalink
[camera] Ensure that channel.invokeMethod runs on the main thread (fl…
Browse files Browse the repository at this point in the history
  • Loading branch information
jsroest authored and Aperico-com committed Feb 3, 2021
1 parent 0f92c7f commit d86f484
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.5+2

* Ensure communication from JAVA to Dart is done on the main UI thread.

## 0.6.5+1

* Fixes picture captures causing a crash on some Huawei devices.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.flutter.plugins.camera;

import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import io.flutter.plugin.common.BinaryMessenger;
Expand Down Expand Up @@ -56,14 +58,39 @@ void sendCameraErrorEvent(@Nullable String description) {
});
}

void send(EventType eventType) {
void send(CameraEventType eventType) {
send(eventType, new HashMap<>());
}

void send(CameraEventType eventType, Map<String, Object> args) {
if (cameraChannel == null) {
return;
}
new Handler(Looper.getMainLooper())
.post(
new Runnable() {
@Override
public void run() {
cameraChannel.invokeMethod(eventType.method, args);
}
});
}

void send(DeviceEventType eventType) {
send(eventType, new HashMap<>());
}

void send(EventType eventType, Map<String, Object> args) {
if (channel == null) {
return;
}
channel.invokeMethod(eventType.toString().toLowerCase(), args);
new Handler(Looper.getMainLooper())
.post(
new Runnable() {
@Override
public void run() {
deviceChannel.invokeMethod(eventType.method, args);
}
});
}
}
2 changes: 1 addition & 1 deletion packages/camera/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera
description: A Flutter plugin for getting information about and controlling the
camera on Android and iOS. Supports previewing the camera feed, capturing images, capturing video,
and streaming image buffers to dart.
version: 0.6.5+1
version: 0.6.5+2
homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera

dependencies:
Expand Down

0 comments on commit d86f484

Please sign in to comment.