Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create list of Pairs?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 static Future<void> sendMessage({
    HashMap? customData
  }) async {
    _eventChannel.invokeMethod('message', {
      'customData': customData
    });
  }

>Solution :

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
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading