diff --git a/build.yaml b/build.yaml
new file mode 100644
index 0000000..cb72314
--- /dev/null
+++ b/build.yaml
@@ -0,0 +1,11 @@
+targets:
+ $default:
+ builders:
+ json_serializable:
+ options:
+ # Options configure how source code is generated for every
+ # `@JsonSerializable`-annotated class in the package.
+ #
+ # The default value for each is listed.
+ any_map: true
+ explicit_to_json: true
\ No newline at end of file
diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist
index 6b4c0f7..4f8d4d2 100644
--- a/example/ios/Flutter/AppFrameworkInfo.plist
+++ b/example/ios/Flutter/AppFrameworkInfo.plist
@@ -21,6 +21,6 @@
CFBundleVersion
1.0
MinimumOSVersion
- 8.0
+ 11.0
diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj
index d59cc08..f683e9f 100644
--- a/example/ios/Runner.xcodeproj/project.pbxproj
+++ b/example/ios/Runner.xcodeproj/project.pbxproj
@@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
- objectVersion = 46;
+ objectVersion = 50;
objects = {
/* Begin PBXBuildFile section */
@@ -135,7 +135,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 1020;
+ LastUpgradeCheck = 1300;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
@@ -280,7 +280,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
@@ -362,7 +362,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
@@ -411,7 +411,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata
index 1d526a1..919434a 100644
--- a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata
+++ b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -2,6 +2,6 @@
+ location = "self:">
diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
index a28140c..3db53b6 100644
--- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
+++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
@@ -1,6 +1,6 @@
UIViewControllerBasedStatusBarAppearance
+ CADisableMinimumFrameDurationOnPhone
+
diff --git a/example/pubspec.lock b/example/pubspec.lock
index 2215551..e0747f6 100644
--- a/example/pubspec.lock
+++ b/example/pubspec.lock
@@ -1,13 +1,34 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
+ _fe_analyzer_shared:
+ dependency: transitive
+ description:
+ name: _fe_analyzer_shared
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "49.0.0"
+ analyzer:
+ dependency: transitive
+ description:
+ name: analyzer
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "5.1.0"
+ args:
+ dependency: transitive
+ description:
+ name: args
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "2.3.1"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
- version: "2.8.2"
+ version: "2.9.0"
boolean_selector:
dependency: transitive
description:
@@ -15,13 +36,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
+ build:
+ dependency: transitive
+ description:
+ name: build
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "2.3.1"
+ build_config:
+ dependency: transitive
+ description:
+ name: build_config
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
- version: "1.2.0"
+ version: "1.2.1"
charcode:
dependency: transitive
description:
@@ -29,20 +64,41 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
+ checked_yaml:
+ dependency: transitive
+ description:
+ name: checked_yaml
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "2.0.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.0"
+ version: "1.1.1"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
- version: "1.15.0"
+ version: "1.16.0"
+ convert:
+ dependency: transitive
+ description:
+ name: convert
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "3.1.1"
+ crypto:
+ dependency: transitive
+ description:
+ name: crypto
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "3.0.2"
cupertino_icons:
dependency: "direct main"
description:
@@ -50,13 +106,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
+ dart_style:
+ dependency: transitive
+ description:
+ name: dart_style
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "2.2.4"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
- version: "1.2.0"
+ version: "1.3.1"
+ file:
+ dependency: transitive
+ description:
+ name: file
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "6.1.4"
flutter:
dependency: "direct main"
description: flutter
@@ -74,6 +144,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
+ glob:
+ dependency: transitive
+ description:
+ name: glob
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "2.1.0"
google_place:
dependency: "direct main"
description:
@@ -95,27 +172,62 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.0"
+ json_annotation:
+ dependency: transitive
+ description:
+ name: json_annotation
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "4.7.0"
+ json_serializable:
+ dependency: transitive
+ description:
+ name: json_serializable
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "6.5.2"
+ logging:
+ dependency: transitive
+ description:
+ name: logging
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.1.0"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
- version: "0.12.11"
+ version: "0.12.12"
+ material_color_utilities:
+ dependency: transitive
+ description:
+ name: material_color_utilities
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "0.1.5"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
- version: "1.7.0"
+ version: "1.8.0"
+ package_config:
+ dependency: transitive
+ description:
+ name: package_config
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "2.1.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
- version: "1.8.0"
+ version: "1.8.2"
pedantic:
dependency: transitive
description:
@@ -123,18 +235,46 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.11.0"
+ pub_semver:
+ dependency: transitive
+ description:
+ name: pub_semver
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "2.1.2"
+ pubspec_parse:
+ dependency: transitive
+ description:
+ name: pubspec_parse
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.2.1"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
+ source_gen:
+ dependency: transitive
+ description:
+ name: source_gen
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.2.6"
+ source_helper:
+ dependency: transitive
+ description:
+ name: source_helper
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.3.3"
source_span:
dependency: transitive
description:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
- version: "1.8.1"
+ version: "1.9.0"
stack_trace:
dependency: transitive
description:
@@ -155,21 +295,21 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.0"
+ version: "1.1.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
- version: "1.2.0"
+ version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
- version: "0.4.3"
+ version: "0.4.12"
typed_data:
dependency: transitive
description:
@@ -183,6 +323,20 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
- version: "2.1.1"
+ version: "2.1.2"
+ watcher:
+ dependency: transitive
+ description:
+ name: watcher
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.0.2"
+ yaml:
+ dependency: transitive
+ description:
+ name: yaml
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "3.1.1"
sdks:
- dart: ">=2.14.0 <3.0.0"
+ dart: ">=2.18.0 <3.0.0"
diff --git a/example/pubspec.yaml b/example/pubspec.yaml
index 90933e5..139825b 100644
--- a/example/pubspec.yaml
+++ b/example/pubspec.yaml
@@ -20,5 +20,4 @@ dev_dependencies:
flutter:
uses-material-design: true
assets:
- - assets/
- - .env
+ - assets/
\ No newline at end of file
diff --git a/lib/google_place.dart b/lib/google_place.dart
index d26814d..e0a4f22 100644
--- a/lib/google_place.dart
+++ b/lib/google_place.dart
@@ -62,7 +62,7 @@ class GooglePlace {
late QueryAutocomplete queryAutocomplete;
/// [timeout] timeout for http call.
- static Duration timeout = Duration(milliseconds: 1500);
+ static Duration timeout = Duration(milliseconds: 3000);
/// Optional headers to pass on each request
final Map headers;
diff --git a/lib/src/autocomplete/autocomplete_prediction.dart b/lib/src/autocomplete/autocomplete_prediction.dart
index d4828f9..afae3d0 100644
--- a/lib/src/autocomplete/autocomplete_prediction.dart
+++ b/lib/src/autocomplete/autocomplete_prediction.dart
@@ -1,7 +1,11 @@
import 'package:google_place/src/models/matched_substring.dart';
import 'package:google_place/src/models/structured_formatting.dart';
import 'package:google_place/src/models/term.dart';
+import 'package:json_annotation/json_annotation.dart';
+part 'autocomplete_prediction.g.dart';
+
+@JsonSerializable()
class AutocompletePrediction {
/// [description] contains the human-readable name for the returned result. For establishment results, this is usually
/// the business name.
@@ -10,6 +14,7 @@ class AutocompletePrediction {
/// [distanceMeters] contains an integer indicating the straight-line distance between the predicted place,
/// and the specified origin point, in meters. This field is only returned when the origin point is specified in the request.
/// This field is not returned in predictions of type route.
+ @JsonKey(name: "distance_meters")
final int? distanceMeters;
/// [id] contains id.
@@ -17,16 +22,19 @@ class AutocompletePrediction {
/// [matchedSubstrings] contains an array with offset value and length. These describe the location of the entered term in
/// the prediction result text, so that the term can be highlighted if desired.
+ @JsonKey(name: "matched_substrings")
final List? matchedSubstrings;
/// [placeId] is a textual identifier that uniquely identifies a place. To retrieve information about the place,
/// pass this identifier in the placeId field of a Places API request. For more information about place IDs.
+ @JsonKey(name: "place_id")
final String? placeId;
/// [reference] contains reference.
final String? reference;
/// [structuredFormatting] provides pre-formatted text that can be shown in your autocomplete results
+ @JsonKey(name: "structured_formatting")
final StructuredFormatting? structuredFormatting;
/// contains an array of terms identifying each section of the returned description
@@ -49,27 +57,8 @@ class AutocompletePrediction {
this.types,
});
- factory AutocompletePrediction.fromJson(Map json) {
- return AutocompletePrediction(
- description: json['description'] as String?,
- distanceMeters: json['distance_meters'] as int?,
- id: json['id'] as String?,
- matchedSubstrings: json['matched_substrings'] != null
- ? json['matched_substrings']
- .map((json) => MatchedSubstring.fromJson(json))
- .toList()
- : null,
- placeId: json['place_id'] as String?,
- reference: json['reference'] as String?,
- structuredFormatting: json['structured_formatting'] != null
- ? StructuredFormatting.fromJson(json['structured_formatting'])
- : null,
- terms: json['terms'] != null
- ? json['terms'].map((json) => Term.fromJson(json)).toList()
- : null,
- types: json['types'] != null
- ? (json['types'] as List).cast()
- : null,
- );
- }
+ factory AutocompletePrediction.fromJson(Map json) =>
+ _$AutocompletePredictionFromJson(json);
+
+ Map toJson() => _$AutocompletePredictionToJson(this);
}
diff --git a/lib/src/autocomplete/autocomplete_prediction.g.dart b/lib/src/autocomplete/autocomplete_prediction.g.dart
new file mode 100644
index 0000000..4c0b87d
--- /dev/null
+++ b/lib/src/autocomplete/autocomplete_prediction.g.dart
@@ -0,0 +1,44 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'autocomplete_prediction.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+AutocompletePrediction _$AutocompletePredictionFromJson(Map json) =>
+ AutocompletePrediction(
+ description: json['description'] as String?,
+ distanceMeters: json['distance_meters'] as int?,
+ id: json['id'] as String?,
+ matchedSubstrings: (json['matched_substrings'] as List?)
+ ?.map((e) =>
+ MatchedSubstring.fromJson(Map.from(e as Map)))
+ .toList(),
+ placeId: json['place_id'] as String?,
+ reference: json['reference'] as String?,
+ structuredFormatting: json['structured_formatting'] == null
+ ? null
+ : StructuredFormatting.fromJson(
+ Map.from(json['structured_formatting'] as Map)),
+ terms: (json['terms'] as List?)
+ ?.map((e) => Term.fromJson(Map.from(e as Map)))
+ .toList(),
+ types:
+ (json['types'] as List?)?.map((e) => e as String).toList(),
+ );
+
+Map _$AutocompletePredictionToJson(
+ AutocompletePrediction instance) =>
+ {
+ 'description': instance.description,
+ 'distance_meters': instance.distanceMeters,
+ 'id': instance.id,
+ 'matched_substrings':
+ instance.matchedSubstrings?.map((e) => e.toJson()).toList(),
+ 'place_id': instance.placeId,
+ 'reference': instance.reference,
+ 'structured_formatting': instance.structuredFormatting?.toJson(),
+ 'terms': instance.terms?.map((e) => e.toJson()).toList(),
+ 'types': instance.types,
+ };
diff --git a/lib/src/autocomplete/autocomplete_response.dart b/lib/src/autocomplete/autocomplete_response.dart
index 7490aba..3e0c72d 100644
--- a/lib/src/autocomplete/autocomplete_response.dart
+++ b/lib/src/autocomplete/autocomplete_response.dart
@@ -1,25 +1,22 @@
import 'dart:convert';
import 'package:google_place/src/autocomplete/autocomplete_prediction.dart';
+import 'package:json_annotation/json_annotation.dart';
+
+part 'autocomplete_response.g.dart';
/// The Autocomplete response contains place predictions and status
+@JsonSerializable()
class AutocompleteResponse {
final String? status;
final List? predictions;
AutocompleteResponse({this.status, this.predictions});
- factory AutocompleteResponse.fromJson(Map json) {
- return AutocompleteResponse(
- status: json['status'] as String?,
- predictions: json['predictions'] != null
- ? json['predictions']
- .map(
- (json) => AutocompletePrediction.fromJson(json))
- .toList()
- : null,
- );
- }
+ factory AutocompleteResponse.fromJson(Map json) =>
+ _$AutocompleteResponseFromJson(json);
+
+ Map toJson() => _$AutocompleteResponseToJson(this);
static AutocompleteResponse parseAutocompleteResult(String responseBody) {
final parsed = json.decode(responseBody).cast();
diff --git a/lib/src/autocomplete/autocomplete_response.g.dart b/lib/src/autocomplete/autocomplete_response.g.dart
new file mode 100644
index 0000000..def30e1
--- /dev/null
+++ b/lib/src/autocomplete/autocomplete_response.g.dart
@@ -0,0 +1,23 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'autocomplete_response.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+AutocompleteResponse _$AutocompleteResponseFromJson(Map json) =>
+ AutocompleteResponse(
+ status: json['status'] as String?,
+ predictions: (json['predictions'] as List?)
+ ?.map((e) => AutocompletePrediction.fromJson(
+ Map.from(e as Map)))
+ .toList(),
+ );
+
+Map _$AutocompleteResponseToJson(
+ AutocompleteResponse instance) =>
+ {
+ 'status': instance.status,
+ 'predictions': instance.predictions?.map((e) => e.toJson()).toList(),
+ };
diff --git a/lib/src/details/details_response.dart b/lib/src/details/details_response.dart
index 0781cc7..0bcc269 100644
--- a/lib/src/details/details_response.dart
+++ b/lib/src/details/details_response.dart
@@ -1,10 +1,15 @@
import 'dart:convert';
import 'package:google_place/src/details/details_result.dart';
+import 'package:json_annotation/json_annotation.dart';
+
+part 'details_response.g.dart';
/// The Details response contains html Attributions and details and status
+@JsonSerializable()
class DetailsResponse {
final String? status;
+ @JsonKey(name: "html_attributions")
final List? htmlAttributions;
final DetailsResult? result;
@@ -13,18 +18,10 @@ class DetailsResponse {
this.htmlAttributions,
this.result,
});
+ factory DetailsResponse.fromJson(Map json) =>
+ _$DetailsResponseFromJson(json);
- factory DetailsResponse.fromJson(Map json) {
- return DetailsResponse(
- status: json['status'],
- htmlAttributions: json['html_attributions'] != null
- ? (json['html_attributions'] as List).cast()
- : null,
- result: json['result'] != null
- ? DetailsResult.fromJson(json['result'])
- : null,
- );
- }
+ Map toJson() => _$DetailsResponseToJson(this);
static DetailsResponse parseDetailsResult(String responseBody) {
final parsed = json.decode(responseBody).cast();
diff --git a/lib/src/details/details_response.g.dart b/lib/src/details/details_response.g.dart
new file mode 100644
index 0000000..14e30a2
--- /dev/null
+++ b/lib/src/details/details_response.g.dart
@@ -0,0 +1,25 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'details_response.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+DetailsResponse _$DetailsResponseFromJson(Map json) => DetailsResponse(
+ status: json['status'] as String?,
+ htmlAttributions: (json['html_attributions'] as List?)
+ ?.map((e) => e as String)
+ .toList(),
+ result: json['result'] == null
+ ? null
+ : DetailsResult.fromJson(
+ Map.from(json['result'] as Map)),
+ );
+
+Map _$DetailsResponseToJson(DetailsResponse instance) =>
+ {
+ 'status': instance.status,
+ 'html_attributions': instance.htmlAttributions,
+ 'result': instance.result?.toJson(),
+ };
diff --git a/lib/src/details/details_result.dart b/lib/src/details/details_result.dart
index 5f157c8..7e805f6 100644
--- a/lib/src/details/details_result.dart
+++ b/lib/src/details/details_result.dart
@@ -4,9 +4,14 @@ import 'package:google_place/src/models/opening_hours.dart';
import 'package:google_place/src/models/photo.dart';
import 'package:google_place/src/models/plus_code.dart';
import 'package:google_place/src/models/review.dart';
+import 'package:json_annotation/json_annotation.dart';
+part 'details_result.g.dart';
+
+@JsonSerializable()
class DetailsResult {
/// [addressComponents] is an array containing the separate components applicable to this address.
+ @JsonKey(name: "address_components")
final List? addressComponents;
/// [businessStatus] indicates the operational status of the place, if it is a business.
@@ -14,16 +19,20 @@ class DetailsResult {
/// OPERATIONAL
/// CLOSED_TEMPORARILY
/// CLOSED_PERMANENTLY
+ @JsonKey(name: "business_status")
final String? businessStatus;
/// [adrAddress] is a representation of the place's address in the adr microformat.
+ @JsonKey(name: "adr_address")
final String? adrAddress;
/// [formattedAddress] is a string containing the human-readable address of this place.
+ @JsonKey(name: "formatted_address")
final String? formattedAddress;
/// [formattedPhoneNumber] contains the place's phone number in its local format. For example,
/// the formatted_phone_number for Google's Sydney, Australia office is (02) 9374 4000.
+ @JsonKey(name: "formatted_phone_number")
final String? formattedPhoneNumber;
/// [geometry] contains Geometry object.
@@ -38,6 +47,7 @@ class DetailsResult {
/// [internationalPhoneNumber] contains the place's phone number in international format.
/// International format includes the country code, and is prefixed with the plus (+) sign.
/// For example, the international_phone_number for Google's Sydney, Australia office is +61 2 9374 4000.
+ @JsonKey(name: "international_phone_number")
final String? internationalPhoneNumber;
/// [name] contains the human-readable name for the returned result. For establishment results,
@@ -45,6 +55,7 @@ class DetailsResult {
final String? name;
/// [geometry] contains OpeningHours object.
+ @JsonKey(name: "opening_hours")
final OpeningHours? openingHours;
/// [photos] an array of photo objects, each containing a reference to an image.
@@ -52,12 +63,14 @@ class DetailsResult {
/// [placeId] A textual identifier that uniquely identifies a place. To retrieve information about the place,
/// pass this identifier in the placeId field of a Places API request. For more information about place IDs.
+ @JsonKey(name: "place_id")
final String? placeId;
/// [plusCode] is an encoded location reference, derived from latitude and longitude coordinates,
/// that represents an area: 1/8000th of a degree by 1/8000th of a degree (about 14m x 14m at the equator) or smaller.
/// Plus codes can be used as a replacement for street addresses in places where they do not exist
/// (where buildings are not numbered or streets are not named).
+ @JsonKey(name: "plus_code")
final PlusCode? plusCode;
/// [rating] contains the place's rating, from 1.0 to 5.0, based on aggregated user reviews.
@@ -83,11 +96,13 @@ class DetailsResult {
final String? url;
/// [userRatingsTotal] is user ratings total.
+ @JsonKey(name: "user_ratings_total")
final int? userRatingsTotal;
/// [utcOffset] contains the number of minutes this place’s current timezone is offset from UTC.
/// For example, for places in Sydney, Australia during daylight saving time this would be 660
/// (+11 hours from UTC), and for places in California outside of daylight saving time this would be -480 (-8 hours from UTC).
+ @JsonKey(name: "utc_offset")
final int? utcOffset;
/// [vicinity] lists a simplified address for the place, including the street name, street number, and locality,
@@ -105,12 +120,14 @@ class DetailsResult {
/// 2 — Moderate
/// 3 — Expensive
/// 4 — Very Expensive
+ @JsonKey(name: "price_level")
final int? priceLevel;
/// [permanentlyClosed] is a boolean flag indicating whether the place has shut down either permanently
/// or temporarily (value true). If the place is operational, or if no data is available, the flag is absent from the response.
@Deprecated(
'permanently_closed is now deprecated. Instead, use business_status to get the operational status of businesses.')
+ @JsonKey(name: "permanently_closed")
final bool? permanentlyClosed;
DetailsResult({
@@ -142,51 +159,8 @@ class DetailsResult {
this.permanentlyClosed,
});
- factory DetailsResult.fromJson(Map json) {
- return DetailsResult(
- addressComponents: json['address_components'] != null
- ? json['address_components']
- .map((json) => AddressComponent.fromJson(json))
- .toList()
- : null,
- businessStatus: json['business_status'],
- adrAddress: json['adr_address'],
- formattedAddress: json['formatted_address'],
- formattedPhoneNumber: json['formatted_phone_number'],
- geometry:
- json['geometry'] != null ? Geometry.fromJson(json['geometry']) : null,
- icon: json['icon'],
- id: json['id'],
- internationalPhoneNumber: json['international_phone_number'],
- name: json['name'],
- openingHours: json['opening_hours'] != null
- ? OpeningHours.fromJson(json['opening_hours'])
- : null,
- photos: json['photos'] != null
- ? json['photos'].map((json) => Photo.fromJson(json)).toList()
- : null,
- placeId: json['place_id'],
- plusCode: json['plus_code'] != null
- ? PlusCode.fromJson(json['plus_code'])
- : null,
- rating: json['rating'] != null ? json['rating'].toDouble() : null,
- reference: json['reference'],
- reviews: json['reviews'] != null
- ? json['reviews']
- .map((json) => Review.fromJson(json))
- .toList()
- : null,
- scope: json['scope'],
- types: json['types'] != null
- ? (json['types'] as List).cast()
- : null,
- url: json['url'],
- userRatingsTotal: json['user_ratings_total'],
- utcOffset: json['utc_offset'],
- vicinity: json['vicinity'],
- website: json['website'],
- priceLevel: json['price_level'],
- permanentlyClosed: json['permanently_closed'],
- );
- }
+ factory DetailsResult.fromJson(Map json) =>
+ _$DetailsResultFromJson(json);
+
+ Map toJson() => _$DetailsResultToJson(this);
}
diff --git a/lib/src/details/details_result.g.dart b/lib/src/details/details_result.g.dart
new file mode 100644
index 0000000..fac06d7
--- /dev/null
+++ b/lib/src/details/details_result.g.dart
@@ -0,0 +1,84 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'details_result.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+DetailsResult _$DetailsResultFromJson(Map json) => DetailsResult(
+ addressComponents: (json['address_components'] as List?)
+ ?.map((e) =>
+ AddressComponent.fromJson(Map.from(e as Map)))
+ .toList(),
+ businessStatus: json['business_status'] as String?,
+ adrAddress: json['adr_address'] as String?,
+ formattedAddress: json['formatted_address'] as String?,
+ formattedPhoneNumber: json['formatted_phone_number'] as String?,
+ geometry: json['geometry'] == null
+ ? null
+ : Geometry.fromJson(
+ Map.from(json['geometry'] as Map)),
+ icon: json['icon'] as String?,
+ id: json['id'] as String?,
+ internationalPhoneNumber: json['international_phone_number'] as String?,
+ name: json['name'] as String?,
+ openingHours: json['opening_hours'] == null
+ ? null
+ : OpeningHours.fromJson(
+ Map.from(json['opening_hours'] as Map)),
+ photos: (json['photos'] as List?)
+ ?.map((e) => Photo.fromJson(Map.from(e as Map)))
+ .toList(),
+ placeId: json['place_id'] as String?,
+ plusCode: json['plus_code'] == null
+ ? null
+ : PlusCode.fromJson(
+ Map.from(json['plus_code'] as Map)),
+ rating: (json['rating'] as num?)?.toDouble(),
+ reference: json['reference'] as String?,
+ reviews: (json['reviews'] as List?)
+ ?.map((e) => Review.fromJson(Map.from(e as Map)))
+ .toList(),
+ scope: json['scope'] as String?,
+ types:
+ (json['types'] as List?)?.map((e) => e as String).toList(),
+ url: json['url'] as String?,
+ userRatingsTotal: json['user_ratings_total'] as int?,
+ utcOffset: json['utc_offset'] as int?,
+ vicinity: json['vicinity'] as String?,
+ website: json['website'] as String?,
+ priceLevel: json['price_level'] as int?,
+ permanentlyClosed: json['permanently_closed'] as bool?,
+ );
+
+Map _$DetailsResultToJson(DetailsResult instance) =>
+ {
+ 'address_components':
+ instance.addressComponents?.map((e) => e.toJson()).toList(),
+ 'business_status': instance.businessStatus,
+ 'adr_address': instance.adrAddress,
+ 'formatted_address': instance.formattedAddress,
+ 'formatted_phone_number': instance.formattedPhoneNumber,
+ 'geometry': instance.geometry?.toJson(),
+ 'icon': instance.icon,
+ 'id': instance.id,
+ 'international_phone_number': instance.internationalPhoneNumber,
+ 'name': instance.name,
+ 'opening_hours': instance.openingHours?.toJson(),
+ 'photos': instance.photos?.map((e) => e.toJson()).toList(),
+ 'place_id': instance.placeId,
+ 'plus_code': instance.plusCode?.toJson(),
+ 'rating': instance.rating,
+ 'reference': instance.reference,
+ 'reviews': instance.reviews?.map((e) => e.toJson()).toList(),
+ 'scope': instance.scope,
+ 'types': instance.types,
+ 'url': instance.url,
+ 'user_ratings_total': instance.userRatingsTotal,
+ 'utc_offset': instance.utcOffset,
+ 'vicinity': instance.vicinity,
+ 'website': instance.website,
+ 'price_level': instance.priceLevel,
+ 'permanently_closed': instance.permanentlyClosed,
+ };
diff --git a/lib/src/models/address_component.dart b/lib/src/models/address_component.dart
index 1e8abe4..c796c0d 100644
--- a/lib/src/models/address_component.dart
+++ b/lib/src/models/address_component.dart
@@ -1,10 +1,17 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'address_component.g.dart';
+
+@JsonSerializable()
class AddressComponent {
/// [longName] is the full text description or name of the address component as returned by the Geocoder.
+ @JsonKey(name: "long_name")
final String? longName;
/// [shortName] is an abbreviated textual name for the address component, if available.
/// For example, an address component for the state of Alaska may have a long_name of "Alaska"
/// and a short_name of "AK" using the 2-letter postal abbreviation.
+ @JsonKey(name: "short_name")
final String? shortName;
/// [types] is an array indicating the type of the address component.
@@ -16,13 +23,8 @@ class AddressComponent {
this.types,
});
- factory AddressComponent.fromJson(Map json) {
- return AddressComponent(
- longName: json['long_name'],
- shortName: json['short_name'],
- types: json['types'] != null
- ? (json['types'] as List).cast()
- : null,
- );
- }
+ factory AddressComponent.fromJson(Map json) =>
+ _$AddressComponentFromJson(json);
+
+ Map toJson() => _$AddressComponentToJson(this);
}
diff --git a/lib/src/models/address_component.g.dart b/lib/src/models/address_component.g.dart
new file mode 100644
index 0000000..b27f2c5
--- /dev/null
+++ b/lib/src/models/address_component.g.dart
@@ -0,0 +1,21 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'address_component.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+AddressComponent _$AddressComponentFromJson(Map json) => AddressComponent(
+ longName: json['long_name'] as String?,
+ shortName: json['short_name'] as String?,
+ types:
+ (json['types'] as List?)?.map((e) => e as String).toList(),
+ );
+
+Map _$AddressComponentToJson(AddressComponent instance) =>
+ {
+ 'long_name': instance.longName,
+ 'short_name': instance.shortName,
+ 'types': instance.types,
+ };
diff --git a/lib/src/models/bounds.dart b/lib/src/models/bounds.dart
index b4df793..72ccbce 100644
--- a/lib/src/models/bounds.dart
+++ b/lib/src/models/bounds.dart
@@ -1,20 +1,17 @@
import 'package:google_place/src/models/northeast.dart';
import 'package:google_place/src/models/southwest.dart';
+import 'package:json_annotation/json_annotation.dart';
+part 'bounds.g.dart';
+
+@JsonSerializable()
class Bounds {
final Northeast? northeast;
final Southwest? southwest;
Bounds({this.northeast, this.southwest});
- factory Bounds.fromJson(Map json) {
- return Bounds(
- northeast: json['northeast'] != null
- ? Northeast.fromJson(json['northeast'])
- : null,
- southwest: json['southwest'] != null
- ? Southwest.fromJson(json['southwest'])
- : null,
- );
- }
+ factory Bounds.fromJson(Map json) => _$BoundsFromJson(json);
+
+ Map toJson() => _$BoundsToJson(this);
}
diff --git a/lib/src/models/bounds.g.dart b/lib/src/models/bounds.g.dart
new file mode 100644
index 0000000..b8de783
--- /dev/null
+++ b/lib/src/models/bounds.g.dart
@@ -0,0 +1,23 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'bounds.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+Bounds _$BoundsFromJson(Map json) => Bounds(
+ northeast: json['northeast'] == null
+ ? null
+ : Northeast.fromJson(
+ Map.from(json['northeast'] as Map)),
+ southwest: json['southwest'] == null
+ ? null
+ : Southwest.fromJson(
+ Map.from(json['southwest'] as Map)),
+ );
+
+Map _$BoundsToJson(Bounds instance) => {
+ 'northeast': instance.northeast?.toJson(),
+ 'southwest': instance.southwest?.toJson(),
+ };
diff --git a/lib/src/models/close.dart b/lib/src/models/close.dart
index 17b8c8e..3eb286c 100644
--- a/lib/src/models/close.dart
+++ b/lib/src/models/close.dart
@@ -1,3 +1,8 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'close.g.dart';
+
+@JsonSerializable()
class Close {
/// [day] a number from 0–6, corresponding to the days of the week, starting on Sunday. For example, 2 means Tuesday.
final int? day;
@@ -8,10 +13,7 @@ class Close {
Close({this.day, this.time});
- factory Close.fromJson(Map json) {
- return Close(
- day: json['day'],
- time: json['time'],
- );
- }
+ factory Close.fromJson(Map json) => _$CloseFromJson(json);
+
+ Map toJson() => _$CloseToJson(this);
}
diff --git a/lib/src/models/close.g.dart b/lib/src/models/close.g.dart
new file mode 100644
index 0000000..35070e9
--- /dev/null
+++ b/lib/src/models/close.g.dart
@@ -0,0 +1,17 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'close.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+Close _$CloseFromJson(Map json) => Close(
+ day: json['day'] as int?,
+ time: json['time'] as String?,
+ );
+
+Map _$CloseToJson(Close instance) => {
+ 'day': instance.day,
+ 'time': instance.time,
+ };
diff --git a/lib/src/models/component.dart b/lib/src/models/component.dart
index 488daa4..6a5b36d 100644
--- a/lib/src/models/component.dart
+++ b/lib/src/models/component.dart
@@ -1,6 +1,16 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'component.g.dart';
+
+@JsonSerializable()
class Component {
final String component;
final String value;
Component(this.component, this.value);
+
+ factory Component.fromJson(Map json) =>
+ _$ComponentFromJson(json);
+
+ Map toJson() => _$ComponentToJson(this);
}
diff --git a/lib/src/models/component.g.dart b/lib/src/models/component.g.dart
new file mode 100644
index 0000000..31850fc
--- /dev/null
+++ b/lib/src/models/component.g.dart
@@ -0,0 +1,17 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'component.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+Component _$ComponentFromJson(Map json) => Component(
+ json['component'] as String,
+ json['value'] as String,
+ );
+
+Map _$ComponentToJson(Component instance) => {
+ 'component': instance.component,
+ 'value': instance.value,
+ };
diff --git a/lib/src/models/debug_log.dart b/lib/src/models/debug_log.dart
index b3084ec..ba2e461 100644
--- a/lib/src/models/debug_log.dart
+++ b/lib/src/models/debug_log.dart
@@ -1,13 +1,15 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'debug_log.g.dart';
+
+@JsonSerializable()
class DebugLog {
final List? line;
DebugLog({this.line});
- factory DebugLog.fromJson(Map json) {
- return DebugLog(
- line: json['line'] != null
- ? (json['line'] as List).cast()
- : null,
- );
- }
+ factory DebugLog.fromJson(Map json) =>
+ _$DebugLogFromJson(json);
+
+ Map toJson() => _$DebugLogToJson(this);
}
diff --git a/lib/src/models/debug_log.g.dart b/lib/src/models/debug_log.g.dart
new file mode 100644
index 0000000..afc2bef
--- /dev/null
+++ b/lib/src/models/debug_log.g.dart
@@ -0,0 +1,15 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'debug_log.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+DebugLog _$DebugLogFromJson(Map json) => DebugLog(
+ line: (json['line'] as List?)?.map((e) => e as String).toList(),
+ );
+
+Map _$DebugLogToJson(DebugLog instance) => {
+ 'line': instance.line,
+ };
diff --git a/lib/src/models/geometry.dart b/lib/src/models/geometry.dart
index 0c1f64e..7cd8033 100644
--- a/lib/src/models/geometry.dart
+++ b/lib/src/models/geometry.dart
@@ -1,7 +1,11 @@
import 'package:google_place/src/models/bounds.dart';
import 'package:google_place/src/models/location.dart';
import 'package:google_place/src/models/viewport.dart';
+import 'package:json_annotation/json_annotation.dart';
+part 'geometry.g.dart';
+
+@JsonSerializable()
class Geometry {
/// [location] contains the geocoded latitude,longitude value for this place.
final Location? location;
@@ -14,13 +18,8 @@ class Geometry {
Geometry({this.location, this.viewport, this.bounds});
- factory Geometry.fromJson(Map json) {
- return Geometry(
- location:
- json['location'] != null ? Location.fromJson(json['location']) : null,
- viewport:
- json['viewport'] != null ? Viewport.fromJson(json['viewport']) : null,
- bounds: json['bounds'] != null ? Bounds.fromJson(json['bounds']) : null,
- );
- }
+ factory Geometry.fromJson(Map json) =>
+ _$GeometryFromJson(json);
+
+ Map toJson() => _$GeometryToJson(this);
}
diff --git a/lib/src/models/geometry.g.dart b/lib/src/models/geometry.g.dart
new file mode 100644
index 0000000..c7baf18
--- /dev/null
+++ b/lib/src/models/geometry.g.dart
@@ -0,0 +1,27 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'geometry.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+Geometry _$GeometryFromJson(Map json) => Geometry(
+ location: json['location'] == null
+ ? null
+ : Location.fromJson(
+ Map.from(json['location'] as Map)),
+ viewport: json['viewport'] == null
+ ? null
+ : Viewport.fromJson(
+ Map.from(json['viewport'] as Map)),
+ bounds: json['bounds'] == null
+ ? null
+ : Bounds.fromJson(Map.from(json['bounds'] as Map)),
+ );
+
+Map _$GeometryToJson(Geometry instance) => {
+ 'location': instance.location?.toJson(),
+ 'viewport': instance.viewport?.toJson(),
+ 'bounds': instance.bounds?.toJson(),
+ };
diff --git a/lib/src/models/lat_lon.dart b/lib/src/models/lat_lon.dart
index 6343dd3..28fd769 100644
--- a/lib/src/models/lat_lon.dart
+++ b/lib/src/models/lat_lon.dart
@@ -1,4 +1,10 @@
+import 'package:json_annotation/json_annotation.dart';
+
/// A pair of latitude and longitude coordinates, stored as degrees.
+
+part 'lat_lon.g.dart';
+
+@JsonSerializable()
class LatLon {
/// Creates a geographical location specified in degrees [latitude] and
/// [longitude].
@@ -20,4 +26,8 @@ class LatLon {
@override
String toString() => '$runtimeType($latitude, $longitude)';
+
+ factory LatLon.fromJson(Map json) => _$LatLonFromJson(json);
+
+ Map toJson() => _$LatLonToJson(this);
}
diff --git a/lib/src/models/lat_lon.g.dart b/lib/src/models/lat_lon.g.dart
new file mode 100644
index 0000000..21ef678
--- /dev/null
+++ b/lib/src/models/lat_lon.g.dart
@@ -0,0 +1,17 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'lat_lon.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+LatLon _$LatLonFromJson(Map json) => LatLon(
+ (json['latitude'] as num).toDouble(),
+ (json['longitude'] as num).toDouble(),
+ );
+
+Map _$LatLonToJson(LatLon instance) => {
+ 'latitude': instance.latitude,
+ 'longitude': instance.longitude,
+ };
diff --git a/lib/src/models/location.dart b/lib/src/models/location.dart
index 76ad6f2..b2766da 100644
--- a/lib/src/models/location.dart
+++ b/lib/src/models/location.dart
@@ -1,13 +1,16 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'location.g.dart';
+
+@JsonSerializable()
class Location {
final double? lat;
final double? lng;
Location({this.lat, this.lng});
- factory Location.fromJson(Map json) {
- return Location(
- lat: json['lat'] != null ? json['lat'].toDouble() : null,
- lng: json['lng'] != null ? json['lng'].toDouble() : null,
- );
- }
+ factory Location.fromJson(Map json) =>
+ _$LocationFromJson(json);
+
+ Map toJson() => _$LocationToJson(this);
}
diff --git a/lib/src/models/location.g.dart b/lib/src/models/location.g.dart
new file mode 100644
index 0000000..8bb3f8c
--- /dev/null
+++ b/lib/src/models/location.g.dart
@@ -0,0 +1,17 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'location.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+Location _$LocationFromJson(Map json) => Location(
+ lat: (json['lat'] as num?)?.toDouble(),
+ lng: (json['lng'] as num?)?.toDouble(),
+ );
+
+Map _$LocationToJson(Location instance) => {
+ 'lat': instance.lat,
+ 'lng': instance.lng,
+ };
diff --git a/lib/src/models/locationbias.dart b/lib/src/models/locationbias.dart
index a051f37..20c90ea 100644
--- a/lib/src/models/locationbias.dart
+++ b/lib/src/models/locationbias.dart
@@ -1,8 +1,13 @@
import 'package:google_place/src/models/lat_lon.dart';
+import 'package:json_annotation/json_annotation.dart';
+
+part 'locationbias.g.dart';
/// [Locationbias] - Prefer results in a specified area, by specifying either a radius plus lat/lng,
/// or two lat/lng pairs representing the points of a rectangle.
/// If this parameter is not specified, the API uses IP address biasing by default.
+
+@JsonSerializable()
class Locationbias {
/// [ipbias] - Instructs the API to use IP address biasing.
final bool? ipbias;
@@ -41,18 +46,35 @@ class Locationbias {
if (ipbias == null || ipbias!)
assert(point != null && circular != null && rectangular != null);
}
+ factory Locationbias.fromJson(Map json) =>
+ _$LocationbiasFromJson(json);
+
+ Map toJson() => _$LocationbiasToJson(this);
}
+@JsonSerializable()
class Circular {
final int radius;
+ @JsonKey(name: "lat_lng")
final LatLon latLng;
Circular(this.radius, this.latLng);
+ factory Circular.fromJson(Map json) =>
+ _$CircularFromJson(json);
+
+ Map toJson() => _$CircularToJson(this);
}
+@JsonSerializable()
class Rectangular {
+ @JsonKey(name: "south_west")
final LatLon southWest;
+ @JsonKey(name: "north_east")
final LatLon northEast;
Rectangular(this.southWest, this.northEast);
+ factory Rectangular.fromJson(Map json) =>
+ _$RectangularFromJson(json);
+
+ Map toJson() => _$RectangularToJson(this);
}
diff --git a/lib/src/models/locationbias.g.dart b/lib/src/models/locationbias.g.dart
new file mode 100644
index 0000000..c4901bf
--- /dev/null
+++ b/lib/src/models/locationbias.g.dart
@@ -0,0 +1,51 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'locationbias.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+Locationbias _$LocationbiasFromJson(Map json) => Locationbias(
+ ipbias: json['ipbias'] as bool?,
+ point: json['point'] == null
+ ? null
+ : LatLon.fromJson(Map.from(json['point'] as Map)),
+ circular: json['circular'] == null
+ ? null
+ : Circular.fromJson(
+ Map.from(json['circular'] as Map)),
+ rectangular: json['rectangular'] == null
+ ? null
+ : Rectangular.fromJson(
+ Map.from(json['rectangular'] as Map)),
+ );
+
+Map _$LocationbiasToJson(Locationbias instance) =>
+ {
+ 'ipbias': instance.ipbias,
+ 'point': instance.point?.toJson(),
+ 'circular': instance.circular?.toJson(),
+ 'rectangular': instance.rectangular?.toJson(),
+ };
+
+Circular _$CircularFromJson(Map json) => Circular(
+ json['radius'] as int,
+ LatLon.fromJson(Map.from(json['lat_lng'] as Map)),
+ );
+
+Map _$CircularToJson(Circular instance) => {
+ 'radius': instance.radius,
+ 'lat_lng': instance.latLng.toJson(),
+ };
+
+Rectangular _$RectangularFromJson(Map json) => Rectangular(
+ LatLon.fromJson(Map.from(json['south_west'] as Map)),
+ LatLon.fromJson(Map.from(json['north_east'] as Map)),
+ );
+
+Map _$RectangularToJson(Rectangular instance) =>
+ {
+ 'south_west': instance.southWest.toJson(),
+ 'north_east': instance.northEast.toJson(),
+ };
diff --git a/lib/src/models/main_text_matched_substring.dart b/lib/src/models/main_text_matched_substring.dart
index f9013f9..fec06b0 100644
--- a/lib/src/models/main_text_matched_substring.dart
+++ b/lib/src/models/main_text_matched_substring.dart
@@ -1,13 +1,16 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'main_text_matched_substring.g.dart';
+
+@JsonSerializable()
class MainTextMatchedSubstring {
final int? length;
final int? offset;
MainTextMatchedSubstring({this.length, this.offset});
- factory MainTextMatchedSubstring.fromJson(Map json) {
- return MainTextMatchedSubstring(
- length: json['length'] as int?,
- offset: json['offset'] as int?,
- );
- }
+ factory MainTextMatchedSubstring.fromJson(Map json) =>
+ _$MainTextMatchedSubstringFromJson(json);
+
+ Map toJson() => _$MainTextMatchedSubstringToJson(this);
}
diff --git a/lib/src/models/main_text_matched_substring.g.dart b/lib/src/models/main_text_matched_substring.g.dart
new file mode 100644
index 0000000..e50274d
--- /dev/null
+++ b/lib/src/models/main_text_matched_substring.g.dart
@@ -0,0 +1,20 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'main_text_matched_substring.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+MainTextMatchedSubstring _$MainTextMatchedSubstringFromJson(Map json) =>
+ MainTextMatchedSubstring(
+ length: json['length'] as int?,
+ offset: json['offset'] as int?,
+ );
+
+Map _$MainTextMatchedSubstringToJson(
+ MainTextMatchedSubstring instance) =>
+ {
+ 'length': instance.length,
+ 'offset': instance.offset,
+ };
diff --git a/lib/src/models/matched_substring.dart b/lib/src/models/matched_substring.dart
index 825dcce..7496606 100644
--- a/lib/src/models/matched_substring.dart
+++ b/lib/src/models/matched_substring.dart
@@ -1,13 +1,16 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'matched_substring.g.dart';
+
+@JsonSerializable()
class MatchedSubstring {
final int? length;
final int? offset;
MatchedSubstring({this.length, this.offset});
- factory MatchedSubstring.fromJson(Map json) {
- return MatchedSubstring(
- length: json['length'] as int?,
- offset: json['offset'] as int?,
- );
- }
+ factory MatchedSubstring.fromJson(Map json) =>
+ _$MatchedSubstringFromJson(json);
+
+ Map toJson() => _$MatchedSubstringToJson(this);
}
diff --git a/lib/src/models/matched_substring.g.dart b/lib/src/models/matched_substring.g.dart
new file mode 100644
index 0000000..46ab701
--- /dev/null
+++ b/lib/src/models/matched_substring.g.dart
@@ -0,0 +1,18 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'matched_substring.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+MatchedSubstring _$MatchedSubstringFromJson(Map json) => MatchedSubstring(
+ length: json['length'] as int?,
+ offset: json['offset'] as int?,
+ );
+
+Map _$MatchedSubstringToJson(MatchedSubstring instance) =>
+ {
+ 'length': instance.length,
+ 'offset': instance.offset,
+ };
diff --git a/lib/src/models/northeast.dart b/lib/src/models/northeast.dart
index 04d20f3..18304bf 100644
--- a/lib/src/models/northeast.dart
+++ b/lib/src/models/northeast.dart
@@ -1,13 +1,16 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'northeast.g.dart';
+
+@JsonSerializable()
class Northeast {
final double? lat;
final double? lng;
Northeast({this.lat, this.lng});
- factory Northeast.fromJson(Map json) {
- return Northeast(
- lat: json['lat'] != null ? json['lat'].toDouble() : null,
- lng: json['lng'] != null ? json['lng'].toDouble() : null,
- );
- }
+ factory Northeast.fromJson(Map json) =>
+ _$NortheastFromJson(json);
+
+ Map toJson() => _$NortheastToJson(this);
}
diff --git a/lib/src/models/northeast.g.dart b/lib/src/models/northeast.g.dart
new file mode 100644
index 0000000..9ff237f
--- /dev/null
+++ b/lib/src/models/northeast.g.dart
@@ -0,0 +1,17 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'northeast.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+Northeast _$NortheastFromJson(Map json) => Northeast(
+ lat: (json['lat'] as num?)?.toDouble(),
+ lng: (json['lng'] as num?)?.toDouble(),
+ );
+
+Map _$NortheastToJson(Northeast instance) => {
+ 'lat': instance.lat,
+ 'lng': instance.lng,
+ };
diff --git a/lib/src/models/open.dart b/lib/src/models/open.dart
index 4469d2c..f673686 100644
--- a/lib/src/models/open.dart
+++ b/lib/src/models/open.dart
@@ -1,3 +1,8 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'open.g.dart';
+
+@JsonSerializable()
class Open {
/// [day] a number from 0–6, corresponding to the days of the week, starting on Sunday. For example, 2 means Tuesday.
final int? day;
@@ -8,10 +13,7 @@ class Open {
Open({this.day, this.time});
- factory Open.fromJson(Map json) {
- return Open(
- day: json['day'],
- time: json['time'],
- );
- }
+ factory Open.fromJson(Map json) => _$OpenFromJson(json);
+
+ Map toJson() => _$OpenToJson(this);
}
diff --git a/lib/src/models/open.g.dart b/lib/src/models/open.g.dart
new file mode 100644
index 0000000..a1a8a53
--- /dev/null
+++ b/lib/src/models/open.g.dart
@@ -0,0 +1,17 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'open.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+Open _$OpenFromJson(Map json) => Open(
+ day: json['day'] as int?,
+ time: json['time'] as String?,
+ );
+
+Map _$OpenToJson(Open instance) => {
+ 'day': instance.day,
+ 'time': instance.time,
+ };
diff --git a/lib/src/models/opening_hours.dart b/lib/src/models/opening_hours.dart
index 4bf01d1..e633677 100644
--- a/lib/src/models/opening_hours.dart
+++ b/lib/src/models/opening_hours.dart
@@ -1,7 +1,12 @@
import 'package:google_place/src/models/period.dart';
+import 'package:json_annotation/json_annotation.dart';
+part 'opening_hours.g.dart';
+
+@JsonSerializable()
class OpeningHours {
/// [openNow] is a boolean value indicating if the place is open at the current time.
+ @JsonKey(name: "open_now")
final bool? openNow;
/// [weekdayText] is an array of seven strings representing the formatted opening hours
@@ -9,6 +14,7 @@ class OpeningHours {
/// the Places Service will format and localize the opening hours appropriately for that language.
/// The ordering of the elements in this array depends on the language parameter.
/// ∂Some languages start the week on Monday while others start on Sunday.
+ @JsonKey(name: "weekday_text")
final List? weekdayText;
/// [periods] is an array of opening periods covering seven days, starting from Sunday, in chronological order.
@@ -20,17 +26,8 @@ class OpeningHours {
this.periods,
});
- factory OpeningHours.fromJson(Map json) {
- return OpeningHours(
- openNow: json['open_now'],
- weekdayText: json['weekday_text'] != null
- ? (json['weekday_text'] as List).cast()
- : null,
- periods: json['periods'] != null
- ? json['periods']
- .map((json) => Period.fromJson(json))
- .toList()
- : null,
- );
- }
+ factory OpeningHours.fromJson(Map json) =>
+ _$OpeningHoursFromJson(json);
+
+ Map toJson() => _$OpeningHoursToJson(this);
}
diff --git a/lib/src/models/opening_hours.g.dart b/lib/src/models/opening_hours.g.dart
new file mode 100644
index 0000000..3cfe9ea
--- /dev/null
+++ b/lib/src/models/opening_hours.g.dart
@@ -0,0 +1,24 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'opening_hours.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+OpeningHours _$OpeningHoursFromJson(Map json) => OpeningHours(
+ openNow: json['open_now'] as bool?,
+ weekdayText: (json['weekday_text'] as List?)
+ ?.map((e) => e as String)
+ .toList(),
+ periods: (json['periods'] as List?)
+ ?.map((e) => Period.fromJson(Map.from(e as Map)))
+ .toList(),
+ );
+
+Map _$OpeningHoursToJson(OpeningHours instance) =>
+ {
+ 'open_now': instance.openNow,
+ 'weekday_text': instance.weekdayText,
+ 'periods': instance.periods?.map((e) => e.toJson()).toList(),
+ };
diff --git a/lib/src/models/period.dart b/lib/src/models/period.dart
index 75cef25..59cd4fd 100644
--- a/lib/src/models/period.dart
+++ b/lib/src/models/period.dart
@@ -1,6 +1,10 @@
import 'package:google_place/src/models/close.dart';
import 'package:google_place/src/models/open.dart';
+import 'package:json_annotation/json_annotation.dart';
+part 'period.g.dart';
+
+@JsonSerializable()
class Period {
/// [close] may contain a pair of day and time objects describing when the place closes.
/// Note: If a place is always open, the close section will be missing from the response.
@@ -13,10 +17,7 @@ class Period {
Period({this.close, this.open});
- factory Period.fromJson(Map json) {
- return Period(
- close: json['close'] != null ? Close.fromJson(json['close']) : null,
- open: json['open'] != null ? Open.fromJson(json['open']) : null,
- );
- }
+ factory Period.fromJson(Map json) => _$PeriodFromJson(json);
+
+ Map toJson() => _$PeriodToJson(this);
}
diff --git a/lib/src/models/period.g.dart b/lib/src/models/period.g.dart
new file mode 100644
index 0000000..b52c3b0
--- /dev/null
+++ b/lib/src/models/period.g.dart
@@ -0,0 +1,21 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'period.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+Period _$PeriodFromJson(Map json) => Period(
+ close: json['close'] == null
+ ? null
+ : Close.fromJson(Map.from(json['close'] as Map)),
+ open: json['open'] == null
+ ? null
+ : Open.fromJson(Map.from(json['open'] as Map)),
+ );
+
+Map _$PeriodToJson(Period instance) => {
+ 'close': instance.close?.toJson(),
+ 'open': instance.open?.toJson(),
+ };
diff --git a/lib/src/models/photo.dart b/lib/src/models/photo.dart
index 23a1e58..a631c1e 100644
--- a/lib/src/models/photo.dart
+++ b/lib/src/models/photo.dart
@@ -1,5 +1,11 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'photo.g.dart';
+
+@JsonSerializable()
class Photo {
/// [photoReference] a string used to identify the photo when you perform a Photo request.
+ @JsonKey(name: "photo_reference")
final String? photoReference;
/// [height] the maximum height of the image.
@@ -9,18 +15,12 @@ class Photo {
final int? width;
/// [htmlAttributions] contains any required attributions. This field will always be present, but may be empty.
+ @JsonKey(name: "html_attributions")
final List? htmlAttributions;
Photo({this.photoReference, this.height, this.width, this.htmlAttributions});
- factory Photo.fromJson(Map json) {
- return Photo(
- photoReference: json['photo_reference'],
- height: json['height'],
- width: json['width'],
- htmlAttributions: json['html_attributions'] != null
- ? (json['html_attributions'] as List).cast()
- : null,
- );
- }
+ factory Photo.fromJson(Map json) => _$PhotoFromJson(json);
+
+ Map toJson() => _$PhotoToJson(this);
}
diff --git a/lib/src/models/photo.g.dart b/lib/src/models/photo.g.dart
new file mode 100644
index 0000000..a7d1e42
--- /dev/null
+++ b/lib/src/models/photo.g.dart
@@ -0,0 +1,23 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'photo.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+Photo _$PhotoFromJson(Map json) => Photo(
+ photoReference: json['photo_reference'] as String?,
+ height: json['height'] as int?,
+ width: json['width'] as int?,
+ htmlAttributions: (json['html_attributions'] as List?)
+ ?.map((e) => e as String)
+ .toList(),
+ );
+
+Map _$PhotoToJson(Photo instance) => {
+ 'photo_reference': instance.photoReference,
+ 'height': instance.height,
+ 'width': instance.width,
+ 'html_attributions': instance.htmlAttributions,
+ };
diff --git a/lib/src/models/plus_code.dart b/lib/src/models/plus_code.dart
index 852cd5b..fcd1353 100644
--- a/lib/src/models/plus_code.dart
+++ b/lib/src/models/plus_code.dart
@@ -1,16 +1,21 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'plus_code.g.dart';
+
+@JsonSerializable()
class PlusCode {
/// [globalCode] is a 4 character area code and 6 character or longer local code (849VCWC8+R9).
+ @JsonKey(name: "global_code")
final String? globalCode;
/// [compoundCode] is a 6 character or longer local code with an explicit location (CWC8+R9, Mountain View, CA, USA).
+ @JsonKey(name: "compound_code")
final String? compoundCode;
PlusCode({this.globalCode, this.compoundCode});
- factory PlusCode.fromJson(Map json) {
- return PlusCode(
- globalCode: json['global_code'],
- compoundCode: json['compound_code'],
- );
- }
+ factory PlusCode.fromJson(Map json) =>
+ _$PlusCodeFromJson(json);
+
+ Map toJson() => _$PlusCodeToJson(this);
}
diff --git a/lib/src/models/plus_code.g.dart b/lib/src/models/plus_code.g.dart
new file mode 100644
index 0000000..6389562
--- /dev/null
+++ b/lib/src/models/plus_code.g.dart
@@ -0,0 +1,17 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'plus_code.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+PlusCode _$PlusCodeFromJson(Map json) => PlusCode(
+ globalCode: json['global_code'] as String?,
+ compoundCode: json['compound_code'] as String?,
+ );
+
+Map _$PlusCodeToJson(PlusCode instance) => {
+ 'global_code': instance.globalCode,
+ 'compound_code': instance.compoundCode,
+ };
diff --git a/lib/src/models/review.dart b/lib/src/models/review.dart
index 224cb27..45289c7 100644
--- a/lib/src/models/review.dart
+++ b/lib/src/models/review.dart
@@ -1,8 +1,15 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'review.g.dart';
+
+@JsonSerializable()
class Review {
/// [authorName] the name of the user who submitted the review. Anonymous reviews are attributed to "A Google user".
+ @JsonKey(name: "author_name")
final String? authorName;
/// [authorUrl] the URL to the user's Google Maps Local Guides profile, if available.
+ @JsonKey(name: "author_url")
final String? authorUrl;
/// [language] an IETF language code indicating the language used in the user's review.
@@ -11,12 +18,14 @@ class Review {
final String? language;
/// [profilePhotoUrl] the URL to the user's profile photo, if available.
+ @JsonKey(name: "profile_photo_url")
final String? profilePhotoUrl;
/// [rating] the user's overall rating for this place. This is a whole number, ranging from 1 to 5.
final int? rating;
/// [relativeTimeDescription] the time that the review was submitted, relative to the current time.
+ @JsonKey(name: "relative_time_description")
final String? relativeTimeDescription;
/// [text] the user's review. When reviewing a location with Google Places, text reviews are considered optional.
@@ -38,16 +47,7 @@ class Review {
this.time,
});
- factory Review.fromJson(Map json) {
- return Review(
- authorName: json['author_name'],
- authorUrl: json['author_url'],
- language: json['language'],
- profilePhotoUrl: json['profile_photo_url'],
- rating: json['rating'],
- relativeTimeDescription: json['relative_time_description'],
- text: json['text'],
- time: json['time'],
- );
- }
+ factory Review.fromJson(Map json) => _$ReviewFromJson(json);
+
+ Map toJson() => _$ReviewToJson(this);
}
diff --git a/lib/src/models/review.g.dart b/lib/src/models/review.g.dart
new file mode 100644
index 0000000..757a777
--- /dev/null
+++ b/lib/src/models/review.g.dart
@@ -0,0 +1,29 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'review.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+Review _$ReviewFromJson(Map json) => Review(
+ authorName: json['author_name'] as String?,
+ authorUrl: json['author_url'] as String?,
+ language: json['language'] as String?,
+ profilePhotoUrl: json['profile_photo_url'] as String?,
+ rating: json['rating'] as int?,
+ relativeTimeDescription: json['relative_time_description'] as String?,
+ text: json['text'] as String?,
+ time: json['time'] as int?,
+ );
+
+Map _$ReviewToJson(Review instance) => {
+ 'author_name': instance.authorName,
+ 'author_url': instance.authorUrl,
+ 'language': instance.language,
+ 'profile_photo_url': instance.profilePhotoUrl,
+ 'rating': instance.rating,
+ 'relative_time_description': instance.relativeTimeDescription,
+ 'text': instance.text,
+ 'time': instance.time,
+ };
diff --git a/lib/src/models/southwest.dart b/lib/src/models/southwest.dart
index 36b08c3..5ed8261 100644
--- a/lib/src/models/southwest.dart
+++ b/lib/src/models/southwest.dart
@@ -1,13 +1,16 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'southwest.g.dart';
+
+@JsonSerializable()
class Southwest {
final double? lat;
final double? lng;
Southwest({this.lat, this.lng});
- factory Southwest.fromJson(Map json) {
- return Southwest(
- lat: json['lat'] != null ? json['lat'].toDouble() : null,
- lng: json['lng'] != null ? json['lng'].toDouble() : null,
- );
- }
+ factory Southwest.fromJson(Map json) =>
+ _$SouthwestFromJson(json);
+
+ Map toJson() => _$SouthwestToJson(this);
}
diff --git a/lib/src/models/southwest.g.dart b/lib/src/models/southwest.g.dart
new file mode 100644
index 0000000..038c9f3
--- /dev/null
+++ b/lib/src/models/southwest.g.dart
@@ -0,0 +1,17 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'southwest.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+Southwest _$SouthwestFromJson(Map json) => Southwest(
+ lat: (json['lat'] as num?)?.toDouble(),
+ lng: (json['lng'] as num?)?.toDouble(),
+ );
+
+Map _$SouthwestToJson(Southwest instance) => {
+ 'lat': instance.lat,
+ 'lng': instance.lng,
+ };
diff --git a/lib/src/models/structured_formatting.dart b/lib/src/models/structured_formatting.dart
index e4e00db..c9baf0a 100644
--- a/lib/src/models/structured_formatting.dart
+++ b/lib/src/models/structured_formatting.dart
@@ -1,28 +1,30 @@
import 'package:google_place/src/models/main_text_matched_substring.dart';
+import 'package:json_annotation/json_annotation.dart';
+
+part 'structured_formatting.g.dart';
+
+@JsonSerializable()
class StructuredFormatting {
/// [mainText] contains the main text of a prediction, usually the name of the place.
+ @JsonKey(name: "main_text")
final String? mainText;
/// [mainTextMatchedSubstrings] contains an array with offset value and length.
/// These describe the location of the entered term in the prediction result text,
/// so that the term can be highlighted if desired.
+ @JsonKey(name: "main_text_matched_substrings")
final List? mainTextMatchedSubstrings;
/// [secondaryText] contains the secondary text of a prediction, usually the location of the place.
+ @JsonKey(name: "secondary_text")
final String? secondaryText;
StructuredFormatting(
{this.mainText, this.mainTextMatchedSubstrings, this.secondaryText});
- factory StructuredFormatting.fromJson(Map json) {
- return StructuredFormatting(
- mainText: json['main_text'] as String?,
- mainTextMatchedSubstrings: json['main_text_matched_substrings']
- .map(
- (json) => MainTextMatchedSubstring.fromJson(json))
- .toList(),
- secondaryText: json['secondary_text'] as String?,
- );
- }
+ factory StructuredFormatting.fromJson(Map json) =>
+ _$StructuredFormattingFromJson(json);
+
+ Map toJson() => _$StructuredFormattingToJson(this);
}
diff --git a/lib/src/models/structured_formatting.g.dart b/lib/src/models/structured_formatting.g.dart
new file mode 100644
index 0000000..cfdc7c1
--- /dev/null
+++ b/lib/src/models/structured_formatting.g.dart
@@ -0,0 +1,27 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'structured_formatting.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+StructuredFormatting _$StructuredFormattingFromJson(Map json) =>
+ StructuredFormatting(
+ mainText: json['main_text'] as String?,
+ mainTextMatchedSubstrings:
+ (json['main_text_matched_substrings'] as List?)
+ ?.map((e) => MainTextMatchedSubstring.fromJson(
+ Map.from(e as Map)))
+ .toList(),
+ secondaryText: json['secondary_text'] as String?,
+ );
+
+Map _$StructuredFormattingToJson(
+ StructuredFormatting instance) =>
+ {
+ 'main_text': instance.mainText,
+ 'main_text_matched_substrings':
+ instance.mainTextMatchedSubstrings?.map((e) => e.toJson()).toList(),
+ 'secondary_text': instance.secondaryText,
+ };
diff --git a/lib/src/models/term.dart b/lib/src/models/term.dart
index 93d8b2a..3f315b9 100644
--- a/lib/src/models/term.dart
+++ b/lib/src/models/term.dart
@@ -1,3 +1,8 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'term.g.dart';
+
+@JsonSerializable()
class Term {
/// [offset] defining the start position of this term in the description
final int? offset;
@@ -7,10 +12,7 @@ class Term {
Term({this.offset, this.value});
- factory Term.fromJson(Map json) {
- return Term(
- offset: json['offset'] as int?,
- value: json['value'] as String?,
- );
- }
+ factory Term.fromJson(Map json) => _$TermFromJson(json);
+
+ Map toJson() => _$TermToJson(this);
}
diff --git a/lib/src/models/term.g.dart b/lib/src/models/term.g.dart
new file mode 100644
index 0000000..68a359c
--- /dev/null
+++ b/lib/src/models/term.g.dart
@@ -0,0 +1,17 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'term.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+Term _$TermFromJson(Map json) => Term(
+ offset: json['offset'] as int?,
+ value: json['value'] as String?,
+ );
+
+Map _$TermToJson(Term instance) => {
+ 'offset': instance.offset,
+ 'value': instance.value,
+ };
diff --git a/lib/src/models/viewport.dart b/lib/src/models/viewport.dart
index 41650d5..a81764c 100644
--- a/lib/src/models/viewport.dart
+++ b/lib/src/models/viewport.dart
@@ -1,20 +1,18 @@
import 'package:google_place/src/models/northeast.dart';
import 'package:google_place/src/models/southwest.dart';
+import 'package:json_annotation/json_annotation.dart';
+part 'viewport.g.dart';
+
+@JsonSerializable()
class Viewport {
final Northeast? northeast;
final Southwest? southwest;
Viewport({this.northeast, this.southwest});
- factory Viewport.fromJson(Map json) {
- return Viewport(
- northeast: json['northeast'] != null
- ? Northeast.fromJson(json['northeast'])
- : null,
- southwest: json['southwest'] != null
- ? Southwest.fromJson(json['southwest'])
- : null,
- );
- }
+ factory Viewport.fromJson(Map json) =>
+ _$ViewportFromJson(json);
+
+ Map toJson() => _$ViewportToJson(this);
}
diff --git a/lib/src/models/viewport.g.dart b/lib/src/models/viewport.g.dart
new file mode 100644
index 0000000..039db9b
--- /dev/null
+++ b/lib/src/models/viewport.g.dart
@@ -0,0 +1,23 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'viewport.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+Viewport _$ViewportFromJson(Map json) => Viewport(
+ northeast: json['northeast'] == null
+ ? null
+ : Northeast.fromJson(
+ Map.from(json['northeast'] as Map)),
+ southwest: json['southwest'] == null
+ ? null
+ : Southwest.fromJson(
+ Map.from(json['southwest'] as Map)),
+ );
+
+Map _$ViewportToJson(Viewport instance) => {
+ 'northeast': instance.northeast?.toJson(),
+ 'southwest': instance.southwest?.toJson(),
+ };
diff --git a/lib/src/photos/photos.dart b/lib/src/photos/photos.dart
index 4e61b53..4663499 100644
--- a/lib/src/photos/photos.dart
+++ b/lib/src/photos/photos.dart
@@ -97,10 +97,15 @@ class Photos {
int? maxWidth,
) {
Map queryParameters = {
- 'photoreference': photoReference,
+ 'photo_reference': photoReference,
'key': apiKEY,
};
- if (maxHeight != null) {}
+ if (maxHeight != null) {
+ var item = {
+ 'maxheight': maxHeight.toString(),
+ };
+ queryParameters.addAll(item);
+ }
if (maxWidth != null) {
var item = {
'maxwidth': maxWidth.toString(),
diff --git a/lib/src/search/find_place_response.dart b/lib/src/search/find_place_response.dart
index 675d5e1..868d873 100644
--- a/lib/src/search/find_place_response.dart
+++ b/lib/src/search/find_place_response.dart
@@ -2,12 +2,20 @@ import 'dart:convert';
import 'package:google_place/src/models/debug_log.dart';
import 'package:google_place/src/search/search_candidate.dart';
+import 'package:json_annotation/json_annotation.dart';
+
+part 'find_place_response.g.dart';
/// The Find Place Search response contains html Attributions and search results and status
+
+@JsonSerializable()
class FindPlaceResponse {
final String? status;
+ @JsonKey(name: "html_attributions")
final List? htmlAttributions;
+ @JsonKey(name: "next_page_token")
final String? nextPageToken;
+ @JsonKey(name: "debug_log")
final DebugLog? debugLog;
final List? candidates;
@@ -19,23 +27,10 @@ class FindPlaceResponse {
this.candidates,
});
- factory FindPlaceResponse.fromJson(Map json) {
- return FindPlaceResponse(
- status: json['status'],
- htmlAttributions: json['html_attributions'] != null
- ? (json['html_attributions'] as List).cast()
- : null,
- nextPageToken: json['next_page_token'],
- debugLog: json['debug_log'] != null
- ? DebugLog.fromJson(json['debug_log'])
- : null,
- candidates: json['candidates'] != null
- ? json['candidates']
- .map((json) => SearchCandidate.fromJson(json))
- .toList()
- : null,
- );
- }
+ factory FindPlaceResponse.fromJson(Map json) =>
+ _$FindPlaceResponseFromJson(json);
+
+ Map toJson() => _$FindPlaceResponseToJson(this);
static FindPlaceResponse parseFindPlaceResult(String responseBody) {
final parsed = json.decode(responseBody).cast();
diff --git a/lib/src/search/find_place_response.g.dart b/lib/src/search/find_place_response.g.dart
new file mode 100644
index 0000000..2f05869
--- /dev/null
+++ b/lib/src/search/find_place_response.g.dart
@@ -0,0 +1,32 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'find_place_response.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+FindPlaceResponse _$FindPlaceResponseFromJson(Map json) => FindPlaceResponse(
+ status: json['status'] as String?,
+ htmlAttributions: (json['html_attributions'] as List?)
+ ?.map((e) => e as String)
+ .toList(),
+ nextPageToken: json['next_page_token'] as String?,
+ debugLog: json['debug_log'] == null
+ ? null
+ : DebugLog.fromJson(
+ Map.from(json['debug_log'] as Map)),
+ candidates: (json['candidates'] as List?)
+ ?.map((e) =>
+ SearchCandidate.fromJson(Map.from(e as Map)))
+ .toList(),
+ );
+
+Map _$FindPlaceResponseToJson(FindPlaceResponse instance) =>
+ {
+ 'status': instance.status,
+ 'html_attributions': instance.htmlAttributions,
+ 'next_page_token': instance.nextPageToken,
+ 'debug_log': instance.debugLog?.toJson(),
+ 'candidates': instance.candidates?.map((e) => e.toJson()).toList(),
+ };
diff --git a/lib/src/search/near_by_search_response.dart b/lib/src/search/near_by_search_response.dart
index 068d636..9e711ee 100644
--- a/lib/src/search/near_by_search_response.dart
+++ b/lib/src/search/near_by_search_response.dart
@@ -2,12 +2,19 @@ import 'dart:convert';
import 'package:google_place/src/models/debug_log.dart';
import 'package:google_place/src/search/search_result.dart';
+import 'package:json_annotation/json_annotation.dart';
+
+part 'near_by_search_response.g.dart';
/// The Near By Search response contains html Attributions and search results and status
+@JsonSerializable()
class NearBySearchResponse {
final String? status;
+ @JsonKey(name: "html_attributions")
final List? htmlAttributions;
+ @JsonKey(name: "next_page_token")
final String? nextPageToken;
+ @JsonKey(name: "debug_log")
final DebugLog? debugLog;
final List? results;
@@ -19,23 +26,10 @@ class NearBySearchResponse {
this.results,
});
- factory NearBySearchResponse.fromJson(Map json) {
- return NearBySearchResponse(
- status: json['status'],
- htmlAttributions: json['html_attributions'] != null
- ? (json['html_attributions'] as List).cast()
- : null,
- nextPageToken: json['next_page_token'],
- debugLog: json['debug_log'] != null
- ? DebugLog.fromJson(json['debug_log'])
- : null,
- results: json['results'] != null
- ? json['results']
- .map((json) => SearchResult.fromJson(json))
- .toList()
- : null,
- );
- }
+ factory NearBySearchResponse.fromJson(Map json) =>
+ _$NearBySearchResponseFromJson(json);
+
+ Map toJson() => _$NearBySearchResponseToJson(this);
static NearBySearchResponse parseNearBySearchResult(String responseBody) {
final parsed = json.decode(responseBody).cast();
diff --git a/lib/src/search/near_by_search_response.g.dart b/lib/src/search/near_by_search_response.g.dart
new file mode 100644
index 0000000..8b3c056
--- /dev/null
+++ b/lib/src/search/near_by_search_response.g.dart
@@ -0,0 +1,34 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'near_by_search_response.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+NearBySearchResponse _$NearBySearchResponseFromJson(Map json) =>
+ NearBySearchResponse(
+ status: json['status'] as String?,
+ htmlAttributions: (json['html_attributions'] as List?)
+ ?.map((e) => e as String)
+ .toList(),
+ nextPageToken: json['next_page_token'] as String?,
+ debugLog: json['debug_log'] == null
+ ? null
+ : DebugLog.fromJson(
+ Map.from(json['debug_log'] as Map)),
+ results: (json['results'] as List?)
+ ?.map(
+ (e) => SearchResult.fromJson(Map.from(e as Map)))
+ .toList(),
+ );
+
+Map _$NearBySearchResponseToJson(
+ NearBySearchResponse instance) =>
+ {
+ 'status': instance.status,
+ 'html_attributions': instance.htmlAttributions,
+ 'next_page_token': instance.nextPageToken,
+ 'debug_log': instance.debugLog?.toJson(),
+ 'results': instance.results?.map((e) => e.toJson()).toList(),
+ };
diff --git a/lib/src/search/search_candidate.dart b/lib/src/search/search_candidate.dart
index 8e77089..ae522f3 100644
--- a/lib/src/search/search_candidate.dart
+++ b/lib/src/search/search_candidate.dart
@@ -2,7 +2,11 @@ import 'package:google_place/src/models/geometry.dart';
import 'package:google_place/src/models/opening_hours.dart';
import 'package:google_place/src/models/photo.dart';
import 'package:google_place/src/models/plus_code.dart';
+import 'package:json_annotation/json_annotation.dart';
+part 'search_candidate.g.dart';
+
+@JsonSerializable()
class SearchCandidate {
/// [geometry] contains geometry information about the result,
/// generally including the location (geocode) of the place and (optionally)
@@ -14,9 +18,11 @@ class SearchCandidate {
/// OPERATIONAL
/// CLOSED_TEMPORARILY
/// CLOSED_PERMANENTLY
+ @JsonKey(name: "business_status")
final String? businessStatus;
/// [openingHours] show opening hours
+ @JsonKey(name: "opening_hours")
final OpeningHours? openingHours;
/// [photos] an array of photo objects, each containing a reference to an image.
@@ -26,10 +32,12 @@ class SearchCandidate {
/// that represents an area: 1/8000th of a degree by 1/8000th of a degree (about 14m x 14m at the equator) or smaller.
/// Plus codes can be used as a replacement for street addresses in places where they do not exist
/// (where buildings are not numbered or streets are not named).
+ @JsonKey(name: "plus_code")
final PlusCode? plusCode;
/// [formattedAddress] is a string containing the human-readable address of this place.
/// Often this address is equivalent to the "postal address".
+ @JsonKey(name: "formatted_address")
final String? formattedAddress;
/// [name] contains the human-readable name for the returned result.
@@ -47,6 +55,7 @@ class SearchCandidate {
/// [placeId] a textual identifier that uniquely identifies a place. To retrieve information about the place,
/// pass this identifier in the placeId field of a Places API request. For more information about place IDs.
+ @JsonKey(name: "place_id")
final String? placeId;
/// [priceLevel] The price level of the place, on a scale of 0 to 4.
@@ -56,6 +65,7 @@ class SearchCandidate {
/// 2 — Moderate
/// 3 — Expensive
/// 4 — Very Expensive
+ @JsonKey(name: "price_level")
final int? priceLevel;
/// [reference] contains reference.
@@ -69,6 +79,7 @@ class SearchCandidate {
final List? types;
/// [userRatingsTotal] is user ratings total.
+ @JsonKey(name: "user_ratings_total")
final int? userRatingsTotal;
/// [vicinity] contains a feature name of a nearby location. Often this feature refers to a street or
@@ -79,6 +90,7 @@ class SearchCandidate {
/// or temporarily (value true). If the place is operational, or if no data is available, the flag is absent from the response.
@Deprecated(
'permanently_closed is now deprecated. Instead, use business_status to get the operational status of businesses.')
+ @JsonKey(name: "permanently_closed")
final bool? permanentlyClosed;
SearchCandidate({
@@ -102,35 +114,8 @@ class SearchCandidate {
this.permanentlyClosed,
});
- factory SearchCandidate.fromJson(Map json) {
- return SearchCandidate(
- geometry:
- json['geometry'] != null ? Geometry.fromJson(json['geometry']) : null,
- businessStatus: json['business_status'],
- openingHours: json['opening_hours'] != null
- ? OpeningHours.fromJson(json['opening_hours'])
- : null,
- photos: json['photos'] != null
- ? json['photos'].map((json) => Photo.fromJson(json)).toList()
- : null,
- plusCode: json['plus_code'] != null
- ? PlusCode.fromJson(json['plus_code'])
- : null,
- formattedAddress: json['formatted_address'],
- name: json['name'],
- rating: json['rating'] != null ? json['rating'].toDouble() : null,
- icon: json['icon'],
- id: json['id'],
- placeId: json['place_id'],
- priceLevel: json['price_level'],
- reference: json['reference'],
- scope: json['scope'],
- types: json['types'] != null
- ? (json['types'] as List).cast()
- : null,
- userRatingsTotal: json['user_ratings_total'],
- vicinity: json['vicinity'],
- permanentlyClosed: json['permanently_closed'],
- );
- }
+ factory SearchCandidate.fromJson(Map json) =>
+ _$SearchCandidateFromJson(json);
+
+ Map toJson() => _$SearchCandidateToJson(this);
}
diff --git a/lib/src/search/search_candidate.g.dart b/lib/src/search/search_candidate.g.dart
new file mode 100644
index 0000000..6e0ee17
--- /dev/null
+++ b/lib/src/search/search_candidate.g.dart
@@ -0,0 +1,62 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'search_candidate.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+SearchCandidate _$SearchCandidateFromJson(Map json) => SearchCandidate(
+ geometry: json['geometry'] == null
+ ? null
+ : Geometry.fromJson(
+ Map.from(json['geometry'] as Map)),
+ businessStatus: json['business_status'] as String?,
+ openingHours: json['opening_hours'] == null
+ ? null
+ : OpeningHours.fromJson(
+ Map.from(json['opening_hours'] as Map)),
+ photos: (json['photos'] as List?)
+ ?.map((e) => Photo.fromJson(Map