Skip to content

Commit

Permalink
Merge pull request #56 from shruti-techindustan/master
Browse files Browse the repository at this point in the history
Filter added by PlaceType and language
  • Loading branch information
Shrutimahajan authored Jul 16, 2024
2 parents a02315b + fa31d28 commit 715a16c
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 56 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@

## 2.0.8

* Bug fixes and improvements
* Bug fixes and improvements

## 2.0.9

* Filter added by PlaceType and language
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ dependencies:
isCrossBtnShown: true,
// optional container padding
containerHorizontalPadding: 10,
// place type
placeType: PlaceType.geocode,
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.example"
minSdkVersion 16
minSdkVersion flutter.minSdkVersion
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
4 changes: 3 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:google_places_flutter/google_places_flutter.dart';
import 'package:google_places_flutter/model/place_type.dart';
import 'package:google_places_flutter/model/prediction.dart';

void main() => runApp(MyApp());
Expand Down Expand Up @@ -71,7 +72,7 @@ class _MyHomePageState extends State<MyHomePage> {
padding: EdgeInsets.symmetric(horizontal: 20),
child: GooglePlaceAutoCompleteTextField(
textEditingController: controller,
googleAPIKey: "YOUR_GOOGLE_API_KEY",
googleAPIKey:"YOUR_GOOGLE_API_KEY",
inputDecoration: InputDecoration(
hintText: "Search your location",
border: InputBorder.none,
Expand All @@ -92,6 +93,7 @@ class _MyHomePageState extends State<MyHomePage> {
seperatedBuilder: Divider(),
containerHorizontalPadding: 10,


// OPTIONAL// If you want to customize list view item builder
itemBuilder: (context, index, Prediction prediction) {
return Container(
Expand Down
68 changes: 46 additions & 22 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.2"
version: "1.18.0"
cupertino_icons:
dependency: "direct main"
description:
Expand Down Expand Up @@ -89,7 +89,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.0.6"
version: "2.0.8"
http_parser:
dependency: transitive
description:
Expand All @@ -98,38 +98,62 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.0"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
url: "https://pub.dev"
source: hosted
version: "10.0.0"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
url: "https://pub.dev"
source: hosted
version: "2.0.1"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
url: "https://pub.dev"
source: hosted
version: "2.0.1"
matcher:
dependency: transitive
description:
name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.dev"
source: hosted
version: "0.12.16"
version: "0.12.16+1"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.5.0"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.11.0"
path:
dependency: transitive
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev"
source: hosted
version: "1.8.3"
version: "1.9.0"
rxdart:
dependency: transitive
description:
Expand All @@ -155,18 +179,18 @@ packages:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
string_scanner:
dependency: transitive
description:
Expand All @@ -187,10 +211,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.6.0"
version: "0.6.1"
typed_data:
dependency: transitive
description:
Expand All @@ -207,13 +231,13 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
vm_service:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
name: vm_service
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
version: "13.0.0"
sdks:
dart: ">=3.1.0-185.0.dev <4.0.0"
dart: ">=3.2.0-0 <4.0.0"
20 changes: 13 additions & 7 deletions lib/google_places_flutter.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
library google_places_flutter;


import 'package:flutter/foundation.dart';
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/place_type.dart';
import 'package:google_places_flutter/model/prediction.dart';

import 'package:rxdart/subjects.dart';
Expand Down Expand Up @@ -33,6 +33,8 @@ class GooglePlaceAutoCompleteTextField extends StatefulWidget {
double? containerHorizontalPadding;
double? containerVerticalPadding;
FocusNode? focusNode;
PlaceType? placeType;
String? language;

GooglePlaceAutoCompleteTextField(
{required this.textEditingController,
Expand All @@ -51,7 +53,8 @@ class GooglePlaceAutoCompleteTextField extends StatefulWidget {
this.showError = true,
this.containerHorizontalPadding,
this.containerVerticalPadding,
this.focusNode});
this.focusNode,
this.placeType,this.language='en'});

@override
_GooglePlaceAutoCompleteTextFieldState createState() =>
Expand Down Expand Up @@ -119,7 +122,7 @@ class _GooglePlaceAutoCompleteTextFieldState

getLocation(String text) async {
String apiURL =
"https://maps.googleapis.com/maps/api/place/autocomplete/json?input=$text&key=${widget.googleAPIKey}";
"https://maps.googleapis.com/maps/api/place/autocomplete/json?input=$text&key=${widget.googleAPIKey}&language=${widget.language}";

if (widget.countries != null) {
// in
Expand All @@ -134,12 +137,16 @@ class _GooglePlaceAutoCompleteTextFieldState
}
}
}
if (widget.placeType != null) {
apiURL += "&types=${widget.placeType?.apiString}";
}

if (_cancelToken?.isCancelled == false) {
_cancelToken?.cancel();
_cancelToken = CancelToken();
}

print("urlll $apiURL");
try {
String proxyURL = "https://cors-anywhere.herokuapp.com/";
String url = kIsWeb ? proxyURL + apiURL : apiURL;
Expand Down Expand Up @@ -255,21 +262,20 @@ class _GooglePlaceAutoCompleteTextFieldState
Future<Response?> getPlaceDetailsFromPlaceId(Prediction prediction) async {
//String key = GlobalConfiguration().getString('google_maps_key');

var url = "https://maps.googleapis.com/maps/api/place/details/json?placeid=${prediction.placeId}&key=${widget.googleAPIKey}";
var url =
"https://maps.googleapis.com/maps/api/place/details/json?placeid=${prediction.placeId}&key=${widget.googleAPIKey}";
try {
Response response = await _dio.get(
url,
);


PlaceDetails placeDetails = PlaceDetails.fromJson(response.data);

prediction.lat = placeDetails.result!.geometry!.location!.lat.toString();
prediction.lng = placeDetails.result!.geometry!.location!.lng.toString();

widget.getPlaceDetailWithLatLng!(prediction);
}
catch(e){
} catch (e) {
var errorHandler = ErrorHandler.internal().handleError(e);
_showSnackBar("${errorHandler.message}");
}
Expand Down
10 changes: 10 additions & 0 deletions lib/model/place_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class PlaceType {
final String apiString;
const PlaceType(this.apiString);

static const geocode = PlaceType("geocode");
static const address = PlaceType("address");
static const establishment = PlaceType("establishment");
static const region = PlaceType("(region)");
static const cities = PlaceType("(cities)");
}
Loading

0 comments on commit 715a16c

Please sign in to comment.