Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass Array of Strings with invokeMethod from Native to 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(){
...
);

but it shows error :

Unsupported value: [Ljava.lang.String .

How can I do that?

like image 833
Saeiddjawadi Avatar asked Jul 15 '19 07:07

Saeiddjawadi


1 Answers

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(){
like image 54
Richard Heap Avatar answered Sep 20 '22 09:09

Richard Heap