Home > Software design >  How do `Map<String, String>` get to know, the `String` endings in `MethodChannel` arguments
How do `Map<String, String>` get to know, the `String` endings in `MethodChannel` arguments

Time:06-15

If dart and kotlin code communicate through binary(array of 8-bit integers (0-255)), then how does String end or even int end is represented in, or determined from binary sequence of bytes, is there some special charCode or something else.

Also is there a way to save a List<int> as-it-is to a file.txt, so it can be read directly to List<int> instead of serialization.

Please guide this new dev, Thanking you...

CodePudding user response:

Since Flutter handles the MethodChannel, in both the Dart side and Kotlin side, it can be allowed to have its own internal protocol to communicate between the native layer and Flutter. In theory they could use JSON but they are probably using something else based on the supported types and also making it more efficient: https://docs.flutter.dev/development/platform-integration/platform-channels?tab=type-mappings-kotlin-tab#codec

For saving a List<int> to a file, you need to determine how you want to encode the content in the file and then how you want to decode it. It can be as simply as just saving each number separated by comma or encode the list into JSON.

If your list of numbers can be represented with Uint8List or Int8List, then you can basically just save the numbers as raw bytes to the file and then read them again.

But List<int> is a list of 64-bit numbers and you should therefore determine how you want to encode this exactly.

For writing to files, there are several ways to do it but the specific way depends on what you exactly want. So without any more details I can just suggest you check the API: https://api.dart.dev/stable/2.17.3/dart-io/File-class.html

  • Related