Skip to content
Open
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
25 changes: 16 additions & 9 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.6.1"
version: "2.8.2"
boolean_selector:
dependency: transitive
description:
Expand All @@ -21,14 +21,14 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.1"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -80,7 +80,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.0.4"
version: "2.0.5"
http_parser:
dependency: transitive
description:
Expand All @@ -94,14 +94,21 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.7.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -162,7 +169,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
version: "0.4.8"
typed_data:
dependency: transitive
description:
Expand All @@ -176,6 +183,6 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
sdks:
dart: ">=2.12.0 <3.0.0"
dart: ">=2.14.0 <3.0.0"
107 changes: 59 additions & 48 deletions lib/google_places_flutter.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
library google_places_flutter;

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_places_flutter/model/place_details.dart';
import 'package:google_places_flutter/model/prediction.dart';

import 'package:rxdart/subjects.dart';
import 'package:dio/dio.dart';
import 'package:rxdart/rxdart.dart';

Expand All @@ -20,19 +16,25 @@ class GooglePlaceAutoCompleteTextField extends StatefulWidget {
TextStyle textStyle;
String googleAPIKey;
int debounceTime = 600;
int? radius ;
double? nearbyAreaLat;
double? nearbyAreaLng;
List<String>? countries = [];
TextEditingController textEditingController = TextEditingController();

GooglePlaceAutoCompleteTextField(
{required this.textEditingController,
required this.googleAPIKey,
this.debounceTime: 600,
this.inputDecoration: const InputDecoration(),
this.itmClick,
this.isLatLngRequired=true,
this.textStyle: const TextStyle(),
this.countries,
this.getPlaceDetailWithLatLng,
required this.googleAPIKey,
this.debounceTime: 600,
this.inputDecoration: const InputDecoration(),
this.itmClick,
this.isLatLngRequired=true,
this.textStyle: const TextStyle(),
this.countries,
this.getPlaceDetailWithLatLng,
this.radius,
this.nearbyAreaLat,
this.nearbyAreaLng,
});

@override
Expand Down Expand Up @@ -75,18 +77,26 @@ class _GooglePlaceAutoCompleteTextFieldState
String country = widget.countries![i];

if (i == 0) {
url = url + "&components=country:$country";
url = url + "&components=country:$country&region=$country";
} else {
url = url + "|" + "country:" + country;
url = url + "|" + "country:" + country + "&regtion=$country";
}
}
}
if (widget.nearbyAreaLat != null && widget.nearbyAreaLng != null) {

url = url + "&location=${widget.nearbyAreaLat}%2C${widget.nearbyAreaLng}";
}
if (widget.radius != null) {

url = url + "&radius=${widget.radius}";
}



Response response = await dio.get(url);
PlacesAutocompleteResponse subscriptionResponse =
PlacesAutocompleteResponse.fromJson(response.data);
PlacesAutocompleteResponse.fromJson(response.data);

if (text.length == 0) {
alPredictions.clear();
Expand Down Expand Up @@ -127,40 +137,40 @@ class _GooglePlaceAutoCompleteTextFieldState
var offset = renderBox.localToGlobal(Offset.zero);
return OverlayEntry(
builder: (context) => Positioned(
left: offset.dx,
top: size.height + offset.dy,
width: size.width,
child: CompositedTransformFollower(
showWhenUnlinked: false,
link: this._layerLink,
offset: Offset(0.0, size.height + 5.0),
child: Material(
elevation: 1.0,
child: ListView.builder(
padding: EdgeInsets.zero,
shrinkWrap: true,
itemCount: alPredictions.length,
itemBuilder: (BuildContext context, int index) {
return InkWell(
onTap: () {
if (index < alPredictions.length) {
widget.itmClick!(alPredictions[index]);
if (!widget.isLatLngRequired) return;

getPlaceDetailsFromPlaceId(
alPredictions[index]);

removeOverlay();
}
},
child: Container(
padding: EdgeInsets.all(10),
child: Text(alPredictions[index].description!)),
);
left: offset.dx,
top: size.height + offset.dy,
width: size.width,
child: CompositedTransformFollower(
showWhenUnlinked: false,
link: this._layerLink,
offset: Offset(0.0, size.height + 5.0),
child: Material(
elevation: 1.0,
child: ListView.builder(
padding: EdgeInsets.zero,
shrinkWrap: true,
itemCount: alPredictions.length,
itemBuilder: (BuildContext context, int index) {
return InkWell(
onTap: () {
if (index < alPredictions.length) {
widget.itmClick!(alPredictions[index]);
if (!widget.isLatLngRequired) return;

getPlaceDetailsFromPlaceId(
alPredictions[index]);

removeOverlay();
}
},
)),
),
));
child: Container(
padding: EdgeInsets.all(10),
child: Text(alPredictions[index].description!)),
);
},
)),
),
));
}
}

Expand Down Expand Up @@ -206,3 +216,4 @@ PlaceDetails parsePlaceDetailMap(Map responseBody) {
typedef ItemClick = void Function(Prediction postalCodeResponse);
typedef GetPlaceDetailswWithLatLng = void Function(
Prediction postalCodeResponse);

23 changes: 15 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.6.1"
version: "2.8.2"
boolean_selector:
dependency: transitive
description:
Expand All @@ -21,14 +21,14 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.1"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -80,14 +80,21 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.7.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -148,7 +155,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
version: "0.4.8"
typed_data:
dependency: transitive
description:
Expand All @@ -162,6 +169,6 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
sdks:
dart: ">=2.12.0 <3.0.0"
dart: ">=2.14.0 <3.0.0"