[BUG | QUESTION] Problems with using SDK with flutter
Closed this issue · 3 comments
Device
- I'm using myPOS Smart N5 with Android 5.1.1
SDK Version
- com.mypos:mypossmartsdk:1.0.4
Is your question related to a problem? Please describe.
I'm developing a flutter plugin library in order to use your myPOS Smart SDK in a flutter application.
I've found some problem when I was using your API for Payment and Refund features.
In particular, when I try to handle the activity result with a callback, I can't send the result to Flutter because when I call result.success(resultStatus) I get a black screen on my application without any error.
Flutter Plugin for myPOS
package com.anmentone.my_poster;
import androidx.annotation.NonNull;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import com.mypos.smartsdk.*;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.content.Context;
import android.app.Activity;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
public class MyPosterPlugin implements FlutterPlugin, MethodCallHandler, ActivityAware {
private MethodChannel channel;
private Context context;
private Activity activity;
private Result result;
private int resultStatus = -1;
@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
context = flutterPluginBinding.getApplicationContext();
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "my_poster");
channel.setMethodCallHandler(this);
}
@Override
public void onAttachedToActivity(ActivityPluginBinding binding) {
activity = binding.getActivity();
binding.addActivityResultListener((int requestCode, int resultCode, Intent data) -> {
IntentLogger.logFullContent(data);
Bundle bundle = data.getExtras();
for (String extraKey : bundle.keySet()) {
if (extraKey.equals("status")) {
resultStatus = Integer.parseInt(bundle.get(extraKey).toString());
}
}
return true;
});
}
@Override
public void onDetachedFromActivity() {
}
@Override
public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding) {
}
@Override
public void onDetachedFromActivityForConfigChanges() {
}
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
this.result = result;
if (call.method.equals("makePayment")) {
double amount = call.argument("amount");
int printCode = call.argument("printCode");
MyPOSPayment payment = MyPOSPayment.builder().productAmount(amount).currency(Currency.EUR)
.printCustomerReceipt(printCode).printMerchantReceipt(printCode).build();
MyPOSAPI.openPaymentActivity(activity, payment, 1);
} else if (call.method.equals("refund")) {
double amount = call.argument("amount");
int printCode = call.argument("printCode");
MyPOSRefund refund = MyPOSRefund.builder().refundAmount(amount).currency(Currency.EUR)
.printCustomerReceipt(printCode).printMerchantReceipt(printCode).build();
MyPOSAPI.openRefundActivity(activity, refund, 2);
} else {
result.notImplemented();
}
}
@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
channel.setMethodCallHandler(null);
}
}
I think, the only way to get the result is made by Result object through success method.
Unfortunately, I don't get any errors in debug mode.
Have you any tips in order to find a solution for this problem?
Let me know if you need more details about.
Hello,
Sorry for the inconvenience!
We are investigating the issue.
Is the result.success(resultStatus) method a heavy operation that might block the main thread of the app causing the black screen?
Kind regards,
MyPOS
Hi, thanks for your reply.
This method exposes an interface for sending results back to Flutter, and it must be called on the platform thread (Android main thread). So I think that it don't block the main thread because is being used by it.
Resolved, there was a bug in my Flutter plugin. Thank you for your time!