首页 > 解决方案 > 如何将带有invokeMethod的字符串数组从Native传递到flutter

问题描述

基于此线程 ,我想将字符串数组作为参数传递,如下所示:

Object obj = new String[] {"Hello","Bye"};
channel.invokeMethod("foo",obj, new MethodChannel.Result(){
...
);

但它显示错误:

不支持的值:[Ljava.lang.String 。

我怎样才能做到这一点?

标签: androidflutter

解决方案


StandardMessageCodec不支持数组(andint除外byte)。对于对象,它支持 Java 集合,例如ListMap. 将您的 String 数组更改为List<String>.

ArrayList<String> args = new ArrayList<>();
args.add("Hello");
args.add("Bye");
channel.invokeMethod("foo", args, new MethodChannel.Result(){

推荐阅读