Skip to content

Commit

Permalink
fix: in web implementation session token is never used during the place
Browse files Browse the repository at this point in the history
autocomplete
  • Loading branch information
mrcsilverfox committed May 21, 2023
1 parent 778b71d commit ad81622
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions flutter_google_places_sdk_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.3+5

* Fix: session token is never used during the place autocomplete

## 0.1.3+4

* Use formatted adrress instead of adr_address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform {
return _completer?.isCompleted == true;
}

AutocompleteSessionToken _getSessionToken({required bool force}) {
final localToken = _lastSessionToken;
if (force || localToken == null) {
return AutocompleteSessionToken();
}
return localToken;
}

@override
Future<FindAutocompletePredictionsResponse> findAutocompletePredictions(
String query, {
Expand All @@ -116,13 +124,15 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform {
// https://issuetracker.google.com/issues/36219203
log("locationRestriction is not supported: https://issuetracker.google.com/issues/36219203");
}
final sessionToken = _getSessionToken(force: newSessionToken == true);
final prom = _svcAutoComplete!.getPlacePredictions(AutocompletionRequest()
..input = query
..origin = origin == null ? null : core.LatLng(origin.lat, origin.lng)
..types = typeFilterStr == null ? null : [typeFilterStr]
..componentRestrictions = (ComponentRestrictions()..country = countries)
..bounds = _boundsToWeb(locationBias)
..language = _language);
..language = _language
..sessionToken = sessionToken);
final resp = await prom;

final predictions = resp.predictions
Expand Down Expand Up @@ -169,10 +179,11 @@ class FlutterGooglePlacesSdkWebPlugin extends FlutterGooglePlacesSdkPlatform {
List<PlaceField>? fields,
bool? newSessionToken,
}) async {
final sessionToken = _getSessionToken(force: newSessionToken == true);
final prom = _getDetails(PlaceDetailsRequest()
..placeId = placeId
..fields = fields?.map(this._mapField).toList(growable: false)
..sessionToken = _lastSessionToken
..sessionToken = sessionToken
..language = _language);

final resp = await prom;
Expand Down
2 changes: 1 addition & 1 deletion 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.3+4
version: 0.1.3+5
homepage: https://github.com/matanshukry/flutter_google_places_sdk/tree/master/flutter_google_places_sdk_web

environment:
Expand Down

0 comments on commit ad81622

Please sign in to comment.