toMap method
Implementation
Map<String, dynamic> toMap() {
final Map<String, dynamic> optionsMap = <String, dynamic>{};
void addIfNonNull(String fieldName, dynamic value) {
if (value != null) {
optionsMap[fieldName] = value;
}
}
List<Map<String, dynamic>>? stepsMap;
if (steps != null) {
stepsMap =
List.generate(steps?.length == null ? 0 : steps!.length, (index) {
return steps![index].toMap();
});
}
addIfNonNull('distance', this.distance);
addIfNonNull('duration', this.duration);
addIfNonNull('summary', this.summary);
addIfNonNull('steps', stepsMap);
addIfNonNull('annotation', this.annotation?.toMap());
return optionsMap;
}