1

I want to create some Pair in Dart (Flutter) e.g.

Pair('text', 'some text here')
Pair('my_value', '233')

and pass it to Android activity (kotlin) via MethodChannel

How Can I do that? I've create a Dart function which takes HashMap but I a bit lost in it and not sure how proceed with that.

 static Future<void> sendMessage({
    HashMap? customData
  }) async {
    _eventChannel.invokeMethod('message', {
      'customData': customData
    });
  }
Richard Heap
  • 48,344
  • 9
  • 130
  • 112
Wafi_ck
  • 1,045
  • 17
  • 41

1 Answers1

1

Just use Map, something like this would work:

final data = <String, dynamic>{'text': 'some text here'};
data['my_value'] = '123';
methodChannel.invokeMethod('method', data);
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
  val arguments = call.arguments as HashMap<String, Any>
  val text = arguments["text"] as String
  val myValue = arguments["my_value"] as String
}
user18309290
  • 5,777
  • 2
  • 4
  • 22