如何将带有invokeMethod的字符串数组从本机传递到flutter [英] How to pass Array of Strings with invokeMethod from Native to flutter
本文介绍了如何将带有invokeMethod的字符串数组从本机传递到flutter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Based On this thread I want to pass array of strings as argument lik this :
Object obj = new String[] {"Hello","Bye"};
channel.invokeMethod("foo",obj, new MethodChannel.Result(){
...
);
但显示错误:
不受支持的值:[Ljava.lang.String.
Unsupported value: [Ljava.lang.String .
我该怎么办?
推荐答案
StandardMessageCodec
不支持数组(int
和byte
除外).对于对象,它支持Java集合,例如List
和Map
.将您的String数组更改为List<String>
.
The StandardMessageCodec
doesn't support arrays (except of int
and byte
). For objects, it supports Java collections, like List
and Map
. Change your array of String to a List<String>
.
ArrayList<String> args = new ArrayList<>();
args.add("Hello");
args.add("Bye");
channel.invokeMethod("foo", args, new MethodChannel.Result(){
这篇关于如何将带有invokeMethod的字符串数组从本机传递到flutter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文