From ecfd4d22ae106621d20a596fc2f6bea4242f4c43 Mon Sep 17 00:00:00 2001 From: Matan Shukry Date: Sun, 1 Sep 2024 16:51:37 +0300 Subject: [PATCH 1/3] upgrade --- .../example/pubspec.yaml | 2 + .../lib/flutter_google_places_sdk_web.dart | 78 +++++++++---------- flutter_google_places_sdk_web/pubspec.yaml | 4 +- 3 files changed, 41 insertions(+), 43 deletions(-) diff --git a/flutter_google_places_sdk/example/pubspec.yaml b/flutter_google_places_sdk/example/pubspec.yaml index 099ec5c..ac38f7b 100644 --- a/flutter_google_places_sdk/example/pubspec.yaml +++ b/flutter_google_places_sdk/example/pubspec.yaml @@ -13,6 +13,8 @@ dependencies: path: ../../flutter_google_places_sdk dependency_overrides: + flutter_google_places_sdk_web: + path: ../../flutter_google_places_sdk_web flutter_google_places_sdk_android: path: ../../flutter_google_places_sdk_android diff --git a/flutter_google_places_sdk_web/lib/flutter_google_places_sdk_web.dart b/flutter_google_places_sdk_web/lib/flutter_google_places_sdk_web.dart index a5c2708..d0017cb 100644 --- a/flutter_google_places_sdk_web/lib/flutter_google_places_sdk_web.dart +++ b/flutter_google_places_sdk_web/lib/flutter_google_places_sdk_web.dart @@ -4,6 +4,7 @@ library places; import 'dart:async'; import 'dart:developer'; import 'dart:html' as html; +import 'dart:js_interop'; import 'dart:js_util'; import 'package:collection/collection.dart'; @@ -13,14 +14,14 @@ import 'package:flutter_google_places_sdk_platform_interface/flutter_google_plac import 'package:flutter_google_places_sdk_platform_interface/flutter_google_places_sdk_platform_interface.dart' as inter; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; -import 'package:google_maps/google_maps.dart'; import 'package:google_maps/google_maps.dart' as core; +import 'package:google_maps/google_maps_geocoding.dart' as geocoding; import 'package:google_maps/google_maps_places.dart' as places; import 'package:google_maps/google_maps_places.dart'; -import 'package:js/js.dart'; +import 'package:web/web.dart' as web; @JS('initMap') -external set _initMap(void Function() f); +external set _initMap(JSFunction f); /// Web implementation plugin for flutter google places sdk class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform { @@ -59,7 +60,7 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform { final completer = Completer(); _completer = completer; - _initMap = allowInterop(_doInit); + _initMap = _doInit.toJS; html.Element? scriptExist = html.window.document.querySelector('#$_SCRIPT_ID'); @@ -91,7 +92,7 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform { void _doInit() { _svcAutoComplete = AutocompleteService(); - _svcPlaces = PlacesService(html.window.document.createElement('div')); + _svcPlaces = PlacesService(html.window.document.createElement('div') as web.HTMLElement); _completer!.complete(); } @@ -119,28 +120,27 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform { ..input = query ..origin = origin == null ? null : core.LatLng(origin.lat, origin.lng) ..types = placeTypesFilter.isEmpty ? null : placeTypesFilter - ..componentRestrictions = (ComponentRestrictions()..country = countries) + ..componentRestrictions = (ComponentRestrictions()..country = countries?.jsify()) ..bounds = _boundsToWeb(locationBias) ..language = _language); final resp = await prom; final predictions = resp.predictions - ?.whereNotNull() + .whereNotNull() .map(_translatePrediction) - .toList(growable: false) ?? - []; + .toList(growable: false); return FindAutocompletePredictionsResponse(predictions); } inter.AutocompletePrediction _translatePrediction( places.AutocompletePrediction prediction) { - var main_text = prediction.structuredFormatting?.mainText; - var secondary_text = prediction.structuredFormatting?.secondaryText; + var main_text = prediction.structuredFormatting.mainText; + var secondary_text = prediction.structuredFormatting.secondaryText; return inter.AutocompletePrediction( distanceMeters: prediction.distanceMeters?.toInt() ?? 0, - placeId: prediction.placeId ?? '', - primaryText: main_text ?? '', - secondaryText: secondary_text ?? '', + placeId: prediction.placeId, + primaryText: main_text, + secondaryText: secondary_text, fullText: '$main_text, $secondary_text', ); } @@ -209,7 +209,7 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform { completer.complete(_GetDetailsResponse(_parsePlace(place), status)); }; - _svcPlaces!.getDetails(request, func); + _svcPlaces!.getDetails(request, func.toJS); return completer.future; } @@ -224,7 +224,7 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform { address: place.formattedAddress, addressComponents: place.addressComponents ?.map(_parseAddressComponent) - .cast() + .cast() .toList(growable: false), businessStatus: _parseBusinessStatus(getProperty(place, 'business_status')), @@ -263,21 +263,20 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform { orElse: () => null); } - AddressComponent? _parseAddressComponent( - GeocoderAddressComponent? addressComponent) { + inter.AddressComponent? _parseAddressComponent( + geocoding.GeocoderAddressComponent? addressComponent) { if (addressComponent == null) { return null; } - return AddressComponent( - name: addressComponent.longName ?? '', - shortName: addressComponent.shortName ?? '', + return inter.AddressComponent( + name: addressComponent.longName, + shortName: addressComponent.shortName, types: addressComponent.types - ?.whereNotNull() + .whereNotNull() .map((e) => e.toString()) .cast() - .toList(growable: false) ?? - [], + .toList(growable: false), ); } @@ -298,11 +297,11 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform { } final htmlAttrs = - photo.htmlAttributions?.whereNotNull().toList(growable: false) ?? []; + photo.htmlAttributions.whereNotNull().toList(growable: false); final photoMetadata = PhotoMetadata( photoReference: _getPhotoMetadataReference(photo), - width: photo.width?.toInt() ?? 0, - height: photo.height?.toInt() ?? 0, + width: photo.width.toInt(), + height: photo.height.toInt(), attributions: htmlAttrs.length == 1 ? htmlAttrs[0] : ''); _photosCache[photoMetadata.photoReference] = photo; @@ -325,14 +324,14 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform { northeast: _parseLatLang(viewport.northEast)!); } - PlusCode? _parsePlusCode(PlacePlusCode? plusCode) { + inter.PlusCode? _parsePlusCode(PlacePlusCode? plusCode) { if (plusCode == null) { return null; } - return PlusCode( + return inter.PlusCode( compoundCode: plusCode.compoundCode ?? '', - globalCode: plusCode.globalCode ?? '', + globalCode: plusCode.globalCode, ); } @@ -346,12 +345,12 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform { (element) => element.name.toUpperCase() == businessStatus); } - OpeningHours? _parseOpeningHours(PlaceOpeningHours? openingHours) { + inter.OpeningHours? _parseOpeningHours(PlaceOpeningHours? openingHours) { if (openingHours == null) { return null; } - return OpeningHours( + return inter.OpeningHours( periods: openingHours.periods ?.whereNotNull() .map(_parsePeriod) @@ -373,20 +372,17 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform { } TimeOfWeek? _parseTimeOfWeek(PlaceOpeningHoursTime? timeOfWeek) { - if (timeOfWeek == null || timeOfWeek.day == null) { + if (timeOfWeek == null) { return null; } - final day = timeOfWeek.day?.toInt(); - if (day == null) { - return null; - } + final day = timeOfWeek.day.toInt(); return TimeOfWeek( day: _parseDayOfWeek(day), time: PlaceLocalTime( - hours: timeOfWeek.hours?.toInt() ?? 0, - minutes: timeOfWeek.minutes?.toInt() ?? 0, + hours: timeOfWeek.hours.toInt(), + minutes: timeOfWeek.minutes.toInt(), ), ); } @@ -425,9 +421,9 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform { final options = PhotoOptions() ..maxWidth = maxWidth ..maxHeight = maxHeight; - final url = value.getUrl(options); + final url = value.url; - return FetchPlacePhotoResponse.imageUrl(url!); + return FetchPlacePhotoResponse.imageUrl(url); } } diff --git a/flutter_google_places_sdk_web/pubspec.yaml b/flutter_google_places_sdk_web/pubspec.yaml index 2ee2a37..967ccf6 100644 --- a/flutter_google_places_sdk_web/pubspec.yaml +++ b/flutter_google_places_sdk_web/pubspec.yaml @@ -13,8 +13,8 @@ dependencies: flutter_web_plugins: sdk: flutter flutter_google_places_sdk_platform_interface: ^0.2.7 - js: ^0.6.7 # Can't upgrade to 0.7.x due to google_maps - google_maps: ^7.1.0 + js: ^0.7.1 + google_maps: ^8.0.0 collection: ^1.17.2 # Can't upgrade to 1.18 due to flutter sdk version dev_dependencies: From e23d1e6b076761ad6520929747bfff4e3dabd985 Mon Sep 17 00:00:00 2001 From: Matan Shukry Date: Sat, 28 Sep 2024 11:15:44 +0300 Subject: [PATCH 2/3] upgrading google maps version to fix the issue --- flutter_google_places_sdk_web/pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flutter_google_places_sdk_web/pubspec.yaml b/flutter_google_places_sdk_web/pubspec.yaml index 967ccf6..332efa9 100644 --- a/flutter_google_places_sdk_web/pubspec.yaml +++ b/flutter_google_places_sdk_web/pubspec.yaml @@ -14,11 +14,11 @@ dependencies: sdk: flutter flutter_google_places_sdk_platform_interface: ^0.2.7 js: ^0.7.1 - google_maps: ^8.0.0 + google_maps: ^8.1.1 collection: ^1.17.2 # Can't upgrade to 1.18 due to flutter sdk version dev_dependencies: - flutter_lints: ^3.0.2 + flutter_lints: ^5.0.0 flutter_test: sdk: flutter mockito: ^5.4.4 From 962468656632c234ddf62c5f691b69b22f5b60b2 Mon Sep 17 00:00:00 2001 From: Matan Shukry Date: Sat, 28 Sep 2024 11:23:38 +0300 Subject: [PATCH 3/3] wip --- flutter_google_places_sdk_web/CHANGELOG.md | 6 ++++++ flutter_google_places_sdk_web/README.md | 7 ++++++- .../lib/flutter_google_places_sdk_web.dart | 3 --- flutter_google_places_sdk_web/pubspec.yaml | 3 ++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/flutter_google_places_sdk_web/CHANGELOG.md b/flutter_google_places_sdk_web/CHANGELOG.md index 2a20dfc..8fc51b2 100644 --- a/flutter_google_places_sdk_web/CHANGELOG.md +++ b/flutter_google_places_sdk_web/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.1.8 + +* Upgrading `google_maps` to ^8.1.1 +* Upgrading `js` to ^0.7.1 +* fetchPlacePhoto will no longer use the maxWidth/maxHeight parameter since they're not available in the getUrl method + ## 0.1.7 * Upgrading `google_maps` to ^7.1.0 diff --git a/flutter_google_places_sdk_web/README.md b/flutter_google_places_sdk_web/README.md index e34776b..f8792de 100644 --- a/flutter_google_places_sdk_web/README.md +++ b/flutter_google_places_sdk_web/README.md @@ -9,6 +9,11 @@ of [`flutter_google_places_web`](https://pub.dartlang.org/packages/flutter_googl ## Restrictions +## fetchPlacePhoto + +* Since `0.1.8`: `fetchPlacePhoto` no longer use the maxWidth/maxHeight parameter since + they're not available in the getUrl method + ### updateSettings -The `updateSettings` method will only update the language. Api Key can not be changed at runtime. \ No newline at end of file +* The `updateSettings` method will only update the language. Api Key can not be changed at runtime. \ No newline at end of file diff --git a/flutter_google_places_sdk_web/lib/flutter_google_places_sdk_web.dart b/flutter_google_places_sdk_web/lib/flutter_google_places_sdk_web.dart index d0017cb..b15b74f 100644 --- a/flutter_google_places_sdk_web/lib/flutter_google_places_sdk_web.dart +++ b/flutter_google_places_sdk_web/lib/flutter_google_places_sdk_web.dart @@ -418,9 +418,6 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform { ); } - final options = PhotoOptions() - ..maxWidth = maxWidth - ..maxHeight = maxHeight; final url = value.url; return FetchPlacePhotoResponse.imageUrl(url); diff --git a/flutter_google_places_sdk_web/pubspec.yaml b/flutter_google_places_sdk_web/pubspec.yaml index 332efa9..cdb0a42 100644 --- a/flutter_google_places_sdk_web/pubspec.yaml +++ b/flutter_google_places_sdk_web/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_google_places_sdk_web description: The web implementation of Flutter plugin for google places sdk -version: 0.1.7 +version: 0.1.8 homepage: https://github.com/matanshukry/flutter_google_places_sdk/tree/master/flutter_google_places_sdk_web environment: @@ -16,6 +16,7 @@ dependencies: js: ^0.7.1 google_maps: ^8.1.1 collection: ^1.17.2 # Can't upgrade to 1.18 due to flutter sdk version + web: ^1.1.0 dev_dependencies: flutter_lints: ^5.0.0