请帮帮我。
我的Flitter插件Java无法从本机android返回列表,请告诉我如何解决。
我创建了一个flatter插件来连接我的手表。我创建了一个方法Chanel来执行android native SDK,但我被卡住了,因为我无法在此函数中将值发送回Flatter,但其他部分工作正常。打扰你们也帮我解决这个问题。
此错误
W/System.err(21058): java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: Binder:21058_2
W/System.err(21058): at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:1280)
W/System.err(21058): at io.flutter.embedding.engine.FlutterJNI.dispatchPlatformMessage(FlutterJNI.java:909)
W/System.err(21058): at io.flutter.embedding.engine.dart.DartMessenger.send(DartMessenger.java:72)
W/System.err(21058): at io.flutter.embedding.engine.dart.DartExecutor$DefaultBinaryMessenger.send(DartExecutor.java:384)
W/System.err(21058): at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:176)
W/System.err(21058): at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler$EventSinkImplementation.success(EventChannel.java:221)
W/System.err(21058): at com.achatsocial.releep_watch_connect.ReleepWatchConnectPlugin$6.onDataResponse(ReleepWatchConnectPlugin.java:259)
W/System.err(21058): at a.b.f(Unknown Source:187)
W/System.err(21058): at a.b.b(Unknown Source:95)
W/System.err(21058): at b.a$a.onCharacteristicChanged(Unknown Source:82)
W/System.err(21058): at android.bluetooth.BluetoothGatt$1$8.run(BluetoothGatt.java:478)
W/System.err(21058): at android.bluetooth.BluetoothGatt.runOrQueueCallback(BluetoothGatt.java:780)
W/System.err(21058): at android.bluetooth.BluetoothGatt.access$200(BluetoothGatt.java:41)
W/System.err(21058): at android.bluetooth.BluetoothGatt$1.onNotify(BluetoothGatt.java:472)
W/System.err(21058): at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:306)
W/System.err(21058): at android.os.Binder.execTransactInternal(Binder.java:1159)
W/System.err(21058): at android.os.Binder.execTransact(Binder.java:1123)
示例My Code Method通道
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
if (call.method.equals("syncHealthData")) {
int dataType = call.argument("dataType");
// ArrayList healthDataList =
// syncHealthDataByDataType(Constants.DATATYPE.Health_HistoryHeart);
ArrayList lists = new ArrayList();
YCBTClient.healthHistoryData(Constants.DATATYPE.Health_HistoryHeart, new BleDataResponse() {
@Override
public void onDataResponse(int i, float v, HashMap hashMap) {
if (hashMap != null) {
lists.addAll((ArrayList) hashMap.get("data"));
android.util.Log.e("history", "hashMap=" + hashMap.toString());
result.success(lists);
} else {
android.util.Log.e("history", "no ..hr..data....");
}
}
});
} else {
result.notImplemented();
}
}
static Future<dynamic> syncHealthHr() async {
var healthDataList =
await _channel.invokeMethod('syncHealthData', {'dataType': 1208});
return healthDataList;
}