Skip to content

Instantly share code, notes, and snippets.

@miguelpruivo
Created July 15, 2019 15:23
Show Gist options
  • Save miguelpruivo/4e5f38ead28c44ae0b83f04370b2814d to your computer and use it in GitHub Desktop.
Save miguelpruivo/4e5f38ead28c44ae0b83f04370b2814d to your computer and use it in GitHub Desktop.
A result wrapper for Flutter Android plugins
package io.ptech.cc.plugins.flutter;
import android.os.Handler;
import android.os.Looper;
import io.flutter.plugin.common.MethodChannel;
public 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(String s, String s1, Object o) {
}
@Override
public void notImplemented() {
handler.post(
new Runnable() {
@Override
public void run() {
methodResult.notImplemented();
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment