diff --git a/example/pubspec.lock b/example/pubspec.lock index 5967b8c..ef9aaf4 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -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: @@ -89,7 +89,7 @@ packages: path: ".." relative: true source: path - version: "2.0.6" + version: "2.0.7" http_parser: dependency: transitive description: @@ -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: @@ -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: @@ -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: @@ -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" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 20d3a3d..f9bb5ac 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -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" diff --git a/lib/google_places_flutter.dart b/lib/google_places_flutter.dart index 8c0320c..cff7963 100644 --- a/lib/google_places_flutter.dart +++ b/lib/google_places_flutter.dart @@ -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? 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? 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() => @@ -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( @@ -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(); @@ -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}"); @@ -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); @@ -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 getPlaceDetailsFromPlaceId(Prediction prediction) async { //String key = GlobalConfiguration().getString('google_maps_key'); @@ -257,6 +268,7 @@ class _GooglePlaceAutoCompleteTextFieldState prediction.lng = placeDetails.result!.geometry!.location!.lng.toString(); widget.getPlaceDetailWithLatLng!(prediction); + return null; } void clearData() { diff --git a/pubspec.lock b/pubspec.lock index 24f995f..58e61b1 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: @@ -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: @@ -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: @@ -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: @@ -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"