toMap method

Map<String, dynamic> toMap()

Implementation

Map<String, dynamic> toMap() {
  final Map<String, dynamic> optionsMap = <String, dynamic>{};

  void addIfNonNull(String fieldName, dynamic value) {
    if (value != null) {
      optionsMap[fieldName] = value;
    }
  }

  addIfNonNull('profile', profile);
  addIfNonNull('resource', resource);
  addIfNonNull('routeType', routeType);

  if (sources.length > 1) {
    int i = 0;
    List<int> sourceIndex = [];
    List<int> destinationIndex = [];
    for (int index = 0; index < sources.length; index++) {
      sourceIndex.add(i);
      i++;
    }

    for (int index = 0; index < destinations.length; index++) {
      destinationIndex.add(i);
      i++;
    }

    addIfNonNull('sources', sourceIndex);
    addIfNonNull('destinations', destinationIndex);
  }

  List<String> coordinateList = [];
  sources.forEach((element) {
    coordinateList.add(element);
  });
  destinations.forEach((element) {
    coordinateList.add(element);
  });
  addIfNonNull('coordinates', coordinateList);
  return optionsMap;
}