Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/image_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.0+3

* Android: fixed assertion failures due to reply messages that were sent on the wrong thread.

## 0.6.0+2

* Android: images are saved with their real extension instead of always using `.jpg`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import android.app.Application;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.VisibleForTesting;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
Expand Down Expand Up @@ -94,12 +96,58 @@ public void onActivityStopped(Activity activity) {}
}
}

// MethodChannel.Result wrapper that responds on the platform thread.
private static class MethodResultWrapper implements MethodChannel.Result {
private MethodChannel.Result methodResult;
private Handler handler;

MethodResultWrapper(MethodChannel.Result result) {
methodResult = result;
handler = new Handler(Looper.getMainLooper());
}

@Override
public void success(final Object result) {
handler.post(
new Runnable() {
@Override
public void run() {
methodResult.success(result);
}
});
}

@Override
public void error(
final String errorCode, final String errorMessage, final Object errorDetails) {
handler.post(
new Runnable() {
@Override
public void run() {
methodResult.error(errorCode, errorMessage, errorDetails);
}
});
}

@Override
public void notImplemented() {
handler.post(
new Runnable() {
@Override
public void run() {
methodResult.notImplemented();
}
});
}
}

@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
public void onMethodCall(MethodCall call, MethodChannel.Result rawResult) {
if (registrar.activity() == null) {
result.error("no_activity", "image_picker plugin requires a foreground activity.", null);
rawResult.error("no_activity", "image_picker plugin requires a foreground activity.", null);
return;
}
MethodChannel.Result result = new MethodResultWrapper(rawResult);
int imageSource;
switch (call.method) {
case METHOD_CALL_IMAGE:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.flutter.plugins.imagepicker;

import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -81,7 +83,7 @@ public void onMethodCall_WhenSourceIsGallery_InvokesChooseImageFromGallery() {

plugin.onMethodCall(call, mockResult);

verify(mockImagePickerDelegate).chooseImageFromGallery(call, mockResult);
verify(mockImagePickerDelegate).chooseImageFromGallery(eq(call), any());
verifyZeroInteractions(mockResult);
}

Expand All @@ -92,7 +94,7 @@ public void onMethodCall_WhenSourceIsCamera_InvokesTakeImageWithCamera() {

plugin.onMethodCall(call, mockResult);

verify(mockImagePickerDelegate).takeImageWithCamera(call, mockResult);
verify(mockImagePickerDelegate).takeImageWithCamera(eq(call), any());
verifyZeroInteractions(mockResult);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/image_picker/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors:
- Flutter Team <flutter-dev@googlegroups.com>
- Rhodes Davis Jr. <rody.davis.jr@gmail.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker
version: 0.6.0+2
version: 0.6.0+3

flutter:
plugin:
Expand Down