toJsonString method

String toJsonString()

A string representation of parameters to call functions of iLib library properly

Implementation

String toJsonString() {
  int? y = year;
  int? m = month;
  int? d = day;
  int? h = hour;
  int? min = minute;
  int? sec = second;
  int? milsec = millisecond;
  String result = '';
  String completeOption = '';

  if (dateTime != null) {
    y = dateTime!.year;
    m = dateTime!.month;
    d = dateTime!.day;
    h = dateTime!.hour;
    min = dateTime!.minute;
    sec = dateTime!.second;
    milsec = dateTime!.millisecond;
  }

  final Map<String, String> paramInfo = <String, String>{
    'locale': '$locale',
    'timezone': '$timezone',
    'type': '$type',
    'calendar': '$calendar'
  };

  paramInfo.forEach((String key, String value) {
    if (value != 'null') {
      result += '$key:"$value",';
    }
  });

  final Map<String, int?> datetimeInfo = <String, int?>{
    'year': y,
    'month': m,
    'day': d,
    'hour': h,
    'minute': min,
    'second': sec,
    'millisecond': milsec,
  };
  datetimeInfo.forEach((String key, int? value) {
    if (value != null) {
      result += '$key:$value,';
    }
  });
  result =
      result.isNotEmpty ? result.substring(0, result.length - 1) : result;
  completeOption = result.isNotEmpty ? '{$result}' : '';
  return completeOption;
}