Locations.fromJson constructor

Locations.fromJson(
  1. Map<String, dynamic>? json
)

Implementation

factory Locations.fromJson(Map<String, dynamic>? json) {
  List<String> fragments = json
          ?.optStringsFromArrayOrSingle("fragments", remove: true)
          .takeIf((it) => it.isNotEmpty) ??
      json?.optStringsFromArrayOrSingle("fragment", remove: true) ??
      [];

  double? progression = json
      ?.optNullableDouble("progression", remove: true)
      ?.takeIf((it) => 0.0 <= it && it <= 1.0);

  int? position =
      json?.optNullableInt("position", remove: true)?.takeIf((it) => it > 0);

  double? totalProgression = json
      ?.optNullableDouble("totalProgression", remove: true)
      ?.takeIf((it) => 0.0 <= it && it <= 1.0);

  return Locations(
      fragments: fragments,
      progression: progression,
      position: position,
      totalProgression: totalProgression,
      otherLocations: json ?? {});
}