@@ -13,19 +13,19 @@ import 'package:rxdart/rxdart.dart';
1313
1414class GooglePlaceAutoCompleteTextField extends StatefulWidget {
1515 InputDecoration inputDecoration;
16- ItemClick itmClick;
17- GetPlaceDetailswWithLatLng getPlaceDetailWithLatLng;
16+ ItemClick ? itmClick;
17+ GetPlaceDetailswWithLatLng ? getPlaceDetailWithLatLng;
1818 bool isLatLngRequired = true ;
1919
2020 TextStyle textStyle;
2121 String googleAPIKey;
2222 int debounceTime = 600 ;
23- List <String > countries = List () ;
23+ List <String >? countries = [] ;
2424 TextEditingController textEditingController = TextEditingController ();
2525
2626 GooglePlaceAutoCompleteTextField (
27- {@ required this .textEditingController,
28- @ required this .googleAPIKey,
27+ {required this .textEditingController,
28+ required this .googleAPIKey,
2929 this .debounceTime: 600 ,
3030 this .inputDecoration: const InputDecoration (),
3131 this .itmClick,
@@ -43,8 +43,8 @@ class GooglePlaceAutoCompleteTextField extends StatefulWidget {
4343class _GooglePlaceAutoCompleteTextFieldState
4444 extends State <GooglePlaceAutoCompleteTextField > {
4545 final subject = new PublishSubject <String >();
46- OverlayEntry _overlayEntry;
47- List <Prediction > alPredictions = new List () ;
46+ OverlayEntry ? _overlayEntry;
47+ List <Prediction > alPredictions = [] ;
4848
4949 TextEditingController controller = TextEditingController ();
5050 final LayerLink _layerLink = LayerLink ();
@@ -71,8 +71,8 @@ class _GooglePlaceAutoCompleteTextFieldState
7171 if (widget.countries != null ) {
7272 // in
7373
74- for (int i = 0 ; i < widget.countries.length; i++ ) {
75- String country = widget.countries[i];
74+ for (int i = 0 ; i < widget.countries! .length; i++ ) {
75+ String country = widget.countries! [i];
7676
7777 if (i == 0 ) {
7878 url = url + "&components=country:$country " ;
@@ -90,21 +90,21 @@ class _GooglePlaceAutoCompleteTextFieldState
9090
9191 if (text.length == 0 ) {
9292 alPredictions.clear ();
93- this ._overlayEntry.remove ();
93+ this ._overlayEntry! .remove ();
9494 return ;
9595 }
9696
9797 isSearched = false ;
98- if (subscriptionResponse.predictions.length > 0 ) {
98+ if (subscriptionResponse.predictions! .length > 0 ) {
9999 alPredictions.clear ();
100- alPredictions.addAll (subscriptionResponse.predictions);
100+ alPredictions.addAll (subscriptionResponse.predictions! );
101101 }
102102
103103 //if (this._overlayEntry == null)
104104
105105 this ._overlayEntry = null ;
106106 this ._overlayEntry = this ._createOverlayEntry ();
107- Overlay .of (context).insert (this ._overlayEntry);
107+ Overlay .of (context)! .insert (this ._overlayEntry! );
108108 // this._overlayEntry.markNeedsBuild();
109109 }
110110
@@ -120,9 +120,9 @@ class _GooglePlaceAutoCompleteTextFieldState
120120 getLocation (text);
121121 }
122122
123- OverlayEntry _createOverlayEntry () {
123+ OverlayEntry ? _createOverlayEntry () {
124124 if (context != null && context.findRenderObject () != null ) {
125- RenderBox renderBox = context.findRenderObject ();
125+ RenderBox renderBox = context.findRenderObject () as RenderBox ;
126126 var size = renderBox.size;
127127 var offset = renderBox.localToGlobal (Offset .zero);
128128 return OverlayEntry (
@@ -144,7 +144,7 @@ class _GooglePlaceAutoCompleteTextFieldState
144144 return InkWell (
145145 onTap: () {
146146 if (index < alPredictions.length) {
147- widget.itmClick (alPredictions[index]);
147+ widget.itmClick ! (alPredictions[index]);
148148 if (! widget.isLatLngRequired) return ;
149149
150150 getPlaceDetailsFromPlaceId (
@@ -155,7 +155,7 @@ class _GooglePlaceAutoCompleteTextFieldState
155155 },
156156 child: Container (
157157 padding: EdgeInsets .all (10 ),
158- child: Text (alPredictions[index].description)),
158+ child: Text (alPredictions[index].description! )),
159159 );
160160 },
161161 )),
@@ -168,12 +168,12 @@ class _GooglePlaceAutoCompleteTextFieldState
168168 alPredictions.clear ();
169169 this ._overlayEntry = this ._createOverlayEntry ();
170170 if (context != null ) {
171- Overlay .of (context).insert (this ._overlayEntry);
172- this ._overlayEntry.markNeedsBuild ();
171+ Overlay .of (context)! .insert (this ._overlayEntry! );
172+ this ._overlayEntry! .markNeedsBuild ();
173173 }
174174 }
175175
176- Future <Response > getPlaceDetailsFromPlaceId (Prediction prediction) async {
176+ Future <Response ? > getPlaceDetailsFromPlaceId (Prediction prediction) async {
177177 //String key = GlobalConfiguration().getString('google_maps_key');
178178
179179 var url =
@@ -184,10 +184,10 @@ class _GooglePlaceAutoCompleteTextFieldState
184184
185185 PlaceDetails placeDetails = PlaceDetails .fromJson (response.data);
186186
187- prediction.lat = placeDetails.result.geometry.location.lat.toString ();
188- prediction.lng = placeDetails.result.geometry.location.lng.toString ();
187+ prediction.lat = placeDetails.result! .geometry! .location! .lat.toString ();
188+ prediction.lng = placeDetails.result! .geometry! .location! .lng.toString ();
189189
190- widget.getPlaceDetailWithLatLng (prediction);
190+ widget.getPlaceDetailWithLatLng ! (prediction);
191191
192192// prediction.latLng = new LatLng(
193193// placeDetails.result.geometry.location.lat,
@@ -196,11 +196,11 @@ class _GooglePlaceAutoCompleteTextFieldState
196196}
197197
198198PlacesAutocompleteResponse parseResponse (Map responseBody) {
199- return PlacesAutocompleteResponse .fromJson (responseBody);
199+ return PlacesAutocompleteResponse .fromJson (responseBody as Map < String , dynamic > );
200200}
201201
202202PlaceDetails parsePlaceDetailMap (Map responseBody) {
203- return PlaceDetails .fromJson (responseBody);
203+ return PlaceDetails .fromJson (responseBody as Map < String , dynamic > );
204204}
205205
206206typedef ItemClick = void Function (Prediction postalCodeResponse);
0 commit comments