Prediction.fromJson constructor

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

Creates a Prediction from JSON data returned by Google Places API.

Parses nested objects like matched_substrings, structured_formatting, and terms arrays into their respective Dart model classes.

Implementation

factory Prediction.fromJson(Map<String, dynamic> json) => Prediction(
      description: json["description"],
      id: json["id"],
      matchedSubstrings: json["matched_substrings"] != null
          ? List<MatchedSubstring>.from(json["matched_substrings"]
              .map((x) => MatchedSubstring.fromJson(x)))
          : null,
      placeId: json["place_id"],
      reference: json["reference"],
      structuredFormatting: json["structured_formatting"] != null
          ? StructuredFormatting.fromJson(json["structured_formatting"])
          : null,
      terms: json["terms"] != null
          ? List<Term>.from(json["terms"].map((x) => Term.fromJson(x)))
          : null,
      types: json["types"] != null
          ? List<String>.from(json["types"].map((x) => x))
          : null,
    );