toMap method

Map<String, int> toMap()

Convert ESPTouchTaskParameter instance to a Map of type Map<String, int>.

Converting to a map is needed for sending information over the platform channels.

You can read more about writing platform-specific code and supported formats for sending data to the hosts (Android and iOS):

We define all values (default or specified) in Dart so that we don't need to handle different default values twice for each platforms.

Implementation

Map<String, int> toMap() {
  // I'm using the ESPTouch library terminology as keys, but tried
  // to use Dart objects and renamed the parameters
  // for creating a more convenient library for Flutter
  return {
    'intervalGuideCodeMillisecond': intervalGuideCode.inMilliseconds,
    'intervalDataCodeMillisecond': intervalDataCode.inMilliseconds,
    'timeoutGuideCodeMillisecond': timeoutGuideCode.inMilliseconds,
    'timeoutDataCodeMillisecond': timeoutDataCode.inMilliseconds,
    'totalRepeatTime': repeat,
    'esptouchResultOneLen': oneLength,
    'esptouchResultMacLen': macLength,
    'esptouchResultIpLen': ipLength,
    'esptouchResultTotalLen': _totalLength,
    'portListening': portListening,
    'targetPort': portTarget,
    'waitUdpReceivingMillisecond': waitUdpReceiving.inMilliseconds,
    'waitUdpSendingMillisecond': waitUdpSending.inMilliseconds,
    'thresholdSucBroadcastCount': thresholdSucBroadcastCount,
    'expectTaskResultCount': expectedTaskResults,
  };
}