toJson method

Object toJson()

Converts this object to something serializable in JSON.

Implementation

Object toJson() {
  final Map<String, Object> json = <String, Object>{};

  void addIfPresent(String fieldName, Object? value) {
    if (value != null) {
      json[fieldName] = value;
    }
  }

  addIfPresent('rendererId', rendererId.value);
  addIfPresent('directions', directions);
  addIfPresent('activedIndex', activedIndex);
  addIfPresent('activeStrokeWidth', activeStrokeWidth);
  addIfPresent('activeStrokeColor', activeStrokeColor.value);
  addIfPresent('activeOutlineWidth', activeOutlineWidth);
  addIfPresent('activeOutlineColor', activeOutlineColor.value);
  addIfPresent('inactiveStrokeWidth', inactiveStrokeWidth);
  addIfPresent('inactiveStrokeColor', inactiveStrokeColor.value);
  addIfPresent('inactiveOutlineWidth', inactiveOutlineWidth);
  addIfPresent('inactiveOutlineColor', inactiveOutlineColor.value);
  addIfPresent('originPOIOptions', originPOIOptions.toJson());
  addIfPresent('destinationPOIOptions', destinationPOIOptions.toJson());

  if (routes != null && routes.length > 0) {
    json['routes'] = _routesToJson();
  }

  return json;
}