Ad

How To Pass Array Of Strings With InvokeMethod From Native To Flutter

- 1 answer

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(){
...
);

but it shows error :

Unsupported value: [Ljava.lang.String .

How can I do that?

Ad

Answer

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(){
Ad
source: stackoverflow.com
Ad