Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade web to 0.1.8 - upgrading google_maps to 8.1.1, and js to 0.7.1 #102

Merged
merged 3 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions flutter_google_places_sdk/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions flutter_google_places_sdk_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 6 additions & 1 deletion flutter_google_places_sdk_web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* The `updateSettings` method will only update the language. Api Key can not be changed at runtime.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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',
);
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -224,7 +224,7 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform {
address: place.formattedAddress,
addressComponents: place.addressComponents
?.map(_parseAddressComponent)
.cast<AddressComponent>()
.cast<inter.AddressComponent>()
.toList(growable: false),
businessStatus:
_parseBusinessStatus(getProperty(place, 'business_status')),
Expand Down Expand Up @@ -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<String>()
.toList(growable: false) ??
[],
.toList(growable: false),
);
}

Expand All @@ -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;
Expand All @@ -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,
);
}

Expand All @@ -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)
Expand All @@ -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(),
),
);
}
Expand Down Expand Up @@ -422,12 +418,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);
}
}

Expand Down
9 changes: 5 additions & 4 deletions flutter_google_places_sdk_web/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -13,12 +13,13 @@ 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.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: ^3.0.2
flutter_lints: ^5.0.0
flutter_test:
sdk: flutter
mockito: ^5.4.4
Expand Down
Loading