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

Add nearby search #50

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
28 changes: 14 additions & 14 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.7"
http_parser:
dependency: transitive
description:
Expand Down Expand Up @@ -118,10 +118,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -155,18 +155,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 +187,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 @@ -211,9 +211,9 @@ packages:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
version: "0.3.0"
sdks:
dart: ">=3.1.0-185.0.dev <4.0.0"
dart: ">=3.2.0-194.0.dev <4.0.0"
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ description: A new Flutter application.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
publish_to: none

environment:
sdk: ">=2.12.0 <4.0.0"
Expand Down
84 changes: 48 additions & 36 deletions lib/google_places_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,59 @@ library google_places_flutter;


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';

import 'DioErrorHandler.dart';

class GooglePlaceAutoCompleteTextField extends StatefulWidget {
InputDecoration inputDecoration;
ItemClick? itemClick;
GetPlaceDetailswWithLatLng? getPlaceDetailWithLatLng;
bool isLatLngRequired = true;

TextStyle textStyle;
String googleAPIKey;
int debounceTime = 600;
List<String>? countries = [];
TextEditingController textEditingController = TextEditingController();
ListItemBuilder? itemBuilder;
Widget? seperatedBuilder;
void clearData;
BoxDecoration? boxDecoration;
bool isCrossBtnShown;
bool showError;
double? containerHorizontalPadding;
double? containerVerticalPadding;

GooglePlaceAutoCompleteTextField(
{required this.textEditingController,
final InputDecoration inputDecoration;
final ItemClick? itemClick;
final GetPlaceDetailswWithLatLng? getPlaceDetailWithLatLng;
final bool isLatLngRequired;

final TextStyle textStyle;
final String googleAPIKey;
final int debounceTime;
final List<String>? countries;
final TextEditingController textEditingController;
final ListItemBuilder? itemBuilder;
final Widget? seperatedBuilder;
final void clearData;
final BoxDecoration? boxDecoration;
final bool isCrossBtnShown;
final bool showError;
final double? containerHorizontalPadding;
final double? containerVerticalPadding;
final double? latitude;
final double? longitude;
/// This is expressed in **meters**
final int? radius;

GooglePlaceAutoCompleteTextField({
required this.textEditingController,
required this.googleAPIKey,
this.debounceTime: 600,
this.inputDecoration: const InputDecoration(),
this.debounceTime = 600,
this.inputDecoration = const InputDecoration(),
this.itemClick,
this.isLatLngRequired = true,
this.textStyle: const TextStyle(),
this.countries,
this.textStyle = const TextStyle(),
this.countries = const [],
this.getPlaceDetailWithLatLng,
this.itemBuilder,
this.boxDecoration,
this.isCrossBtnShown = true,
this.seperatedBuilder,this.showError=true,this
.containerHorizontalPadding,this.containerVerticalPadding});
this.seperatedBuilder,this.showError=true,
this.containerHorizontalPadding,
this.containerVerticalPadding,
this.clearData,
this.latitude,
this.longitude,
this.radius
});

@override
_GooglePlaceAutoCompleteTextFieldState createState() =>
Expand Down Expand Up @@ -77,7 +85,7 @@ class _GooglePlaceAutoCompleteTextFieldState
return CompositedTransformTarget(
link: _layerLink,
child: Container(
padding: EdgeInsets.symmetric(horizontal: widget.containerHorizontalPadding??0, vertical: widget.containerVerticalPadding??0),
padding: EdgeInsets.symmetric(horizontal: widget.containerHorizontalPadding ?? 0, vertical: widget.containerVerticalPadding ?? 0),
alignment: Alignment.centerLeft,
decoration: widget.boxDecoration ??
BoxDecoration(
Expand Down Expand Up @@ -131,6 +139,10 @@ class _GooglePlaceAutoCompleteTextFieldState
}
}

if(widget.latitude != null && widget.longitude != null && widget.radius != null) {
url = url + "&location=${widget.latitude},${widget.longitude}&radius=${widget.radius}";
}

if (_cancelToken?.isCancelled == false) {
_cancelToken?.cancel();
_cancelToken = CancelToken();
Expand Down Expand Up @@ -164,7 +176,7 @@ class _GooglePlaceAutoCompleteTextFieldState

this._overlayEntry = null;
this._overlayEntry = this._createOverlayEntry();
Overlay.of(context)!.insert(this._overlayEntry!);
Overlay.of(context).insert(this._overlayEntry!);
} catch (e) {
var errorHandler = ErrorHandler.internal().handleError(e);
_showSnackBar("${errorHandler.message}");
Expand All @@ -186,7 +198,7 @@ class _GooglePlaceAutoCompleteTextFieldState
}

OverlayEntry? _createOverlayEntry() {
if (context != null && context.findRenderObject() != null) {
if (context.findRenderObject() != null) {
RenderBox renderBox = context.findRenderObject() as RenderBox;
var size = renderBox.size;
var offset = renderBox.localToGlobal(Offset.zero);
Expand Down Expand Up @@ -231,16 +243,15 @@ class _GooglePlaceAutoCompleteTextFieldState
),
));
}
return null;
}

removeOverlay() {
alPredictions.clear();
this._overlayEntry = this._createOverlayEntry();
if (context != null) {
Overlay.of(context).insert(this._overlayEntry!);
this._overlayEntry!.markNeedsBuild();
Overlay.of(context).insert(this._overlayEntry!);
this._overlayEntry!.markNeedsBuild();
}
}

Future<Response?> getPlaceDetailsFromPlaceId(Prediction prediction) async {
//String key = GlobalConfiguration().getString('google_maps_key');
Expand All @@ -257,6 +268,7 @@ class _GooglePlaceAutoCompleteTextFieldState
prediction.lng = placeDetails.result!.geometry!.location!.lng.toString();

widget.getPlaceDetailWithLatLng!(prediction);
return null;
}

void clearData() {
Expand Down
26 changes: 13 additions & 13 deletions 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"
dio:
dependency: "direct main"
description:
Expand Down Expand Up @@ -103,10 +103,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -140,18 +140,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 @@ -172,10 +172,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 @@ -196,9 +196,9 @@ packages:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
version: "0.3.0"
sdks:
dart: ">=3.1.0-185.0.dev <4.0.0"
dart: ">=3.2.0-194.0.dev <4.0.0"