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 4, 2021
1 parent da1b463 commit 3974342
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

## 0.6.4+2

* Set ImageStreamReader listener to null to prevent stale images when streaming images.
* Set ImageStreamReader listener to null to prevent stale images when streaming images.

## 0.6.4+1

Expand Down Expand Up @@ -75,7 +75,7 @@ As part of implementing federated architecture and making the interface compatib

Method changes in `CameraController`:
- The `takePicture` method no longer accepts the `path` parameter, but instead returns the captured image as an instance of the `XFile` class;
- The `startVideoRecording` method no longer accepts the `filePath`. Instead the recorded video is now returned as a `XFile` instance when the `stopVideoRecording` method completes;
- The `startVideoRecording` method no longer accepts the `filePath`. Instead the recorded video is now returned as a `XFile` instance when the `stopVideoRecording` method completes;
- The `stopVideoRecording` method now returns the captured video when it completes;
- Added the `buildPreview` method which is now used to implement the CameraPreview widget.

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);
}
});
}
}

0 comments on commit 3974342

Please sign in to comment.