Skip to content

Commit 23057f7

Browse files
committed
building auto complete address
1 parent 7b5ba68 commit 23057f7

File tree

1 file changed

+88
-46
lines changed

1 file changed

+88
-46
lines changed

lib/screens/tab_screens/checkout_screens/enterAddress.dart

Lines changed: 88 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class EnterAddress extends StatefulWidget {
4040

4141
class _EnterAddressState extends State<EnterAddress> {
4242
Future addressFuture;
43+
Future currentLocation;
44+
var currentLocationAddress;
4345

4446
final UserDataAddress address;
4547
final List<UserDataAddress> addressList;
@@ -60,6 +62,8 @@ class _EnterAddressState extends State<EnterAddress> {
6062
Provider.of<UserDataAddressNotifier>(context, listen: false);
6163
addressFuture = getAddress(addressNotifier);
6264

65+
currentLocation = getUserCurrentLocation();
66+
6367
super.initState();
6468
}
6569

@@ -81,7 +85,9 @@ class _EnterAddressState extends State<EnterAddress> {
8185
}
8286

8387
void getLocationResult(
84-
String input, UserDataAddressNotifier addressNotifier) async {
88+
String input,
89+
UserDataAddressNotifier addressNotifier,
90+
) async {
8591
if (input.isEmpty || _searchController.text.isEmpty) {
8692
setState(() {
8793
showCurrentLocation = true;
@@ -134,6 +140,7 @@ class _EnterAddressState extends State<EnterAddress> {
134140
await Geocoder.local.findAddressesFromCoordinates(coordinates);
135141
var first = addresses.first;
136142
print("${first.featureName} : ${first.addressLine}");
143+
currentLocationAddress = first.addressLine;
137144
} on PlatformException catch (e) {
138145
if (e.code == 'PERMISSION_DENIED') {
139146
error = 'please grant permission';
@@ -212,6 +219,7 @@ class _EnterAddressState extends State<EnterAddress> {
212219
SizedBox(height: 20.0),
213220
Divider(height: 1.0),
214221
SizedBox(height: 20.0),
222+
Spacer(),
215223
Container(
216224
child: FutureBuilder(
217225
future: addressFuture,
@@ -263,51 +271,85 @@ class _EnterAddressState extends State<EnterAddress> {
263271
),
264272
),
265273
SizedBox(height: 10.0),
266-
GestureDetector(
267-
onTap: () {
268-
getUserCurrentLocation();
269-
},
270-
child: Container(
271-
width: MediaQuery.of(context).size.width,
272-
padding: EdgeInsets.all(20.0),
273-
decoration: BoxDecoration(
274-
color: MColors.primaryWhite,
275-
borderRadius: BorderRadius.all(
276-
Radius.circular(10.0),
277-
),
278-
),
279-
child: Column(
280-
children: <Widget>[
281-
Row(
282-
children: <Widget>[
283-
Container(
284-
child: SvgPicture.asset(
285-
"assets/images/icons/Discovery.svg",
286-
color: MColors.primaryPurple,
287-
),
288-
),
289-
SizedBox(width: 5.0),
290-
Expanded(
291-
child: Container(
292-
child: Text(
293-
"Use current location",
294-
style: boldFont(MColors.textDark, 14.0),
295-
),
296-
),
297-
),
298-
],
299-
),
300-
Container(
301-
padding: const EdgeInsets.only(
302-
left: 25.0,
303-
),
304-
child: Text(
305-
"R. Ayres Gama, 222 - AP 701 - Centro, Blumenau - SC, 89012-480",
306-
style: normalFont(MColors.textGrey, 14.0),
307-
),
308-
),
309-
],
310-
),
274+
Container(
275+
child: FutureBuilder(
276+
future: currentLocation,
277+
builder: (c, s) {
278+
switch (s.connectionState) {
279+
case ConnectionState.active:
280+
return Container(
281+
height: MediaQuery.of(context).size.height / 7,
282+
child:
283+
Center(child: progressIndicator(MColors.primaryPurple)),
284+
);
285+
break;
286+
case ConnectionState.done:
287+
return currentLocationAddress.isEmpty
288+
? Container()
289+
: GestureDetector(
290+
onTap: () {
291+
print(currentLocationAddress);
292+
},
293+
child: Container(
294+
width: MediaQuery.of(context).size.width,
295+
padding: EdgeInsets.all(20.0),
296+
decoration: BoxDecoration(
297+
color: MColors.dashPurple,
298+
borderRadius: BorderRadius.all(
299+
Radius.circular(10.0),
300+
),
301+
),
302+
child: Column(
303+
children: <Widget>[
304+
Row(
305+
children: <Widget>[
306+
Container(
307+
child: SvgPicture.asset(
308+
"assets/images/icons/Discovery.svg",
309+
color: MColors.primaryPurple,
310+
),
311+
),
312+
SizedBox(width: 5.0),
313+
Expanded(
314+
child: Container(
315+
child: Text(
316+
"Use current location",
317+
style:
318+
boldFont(MColors.textDark, 14.0),
319+
),
320+
),
321+
),
322+
],
323+
),
324+
Container(
325+
padding: const EdgeInsets.only(
326+
left: 25.0,
327+
),
328+
child: Text(
329+
currentLocationAddress,
330+
style: normalFont(MColors.textGrey, 14.0),
331+
),
332+
),
333+
],
334+
),
335+
),
336+
);
337+
break;
338+
case ConnectionState.waiting:
339+
return Container(
340+
height: MediaQuery.of(context).size.height / 7,
341+
child:
342+
Center(child: progressIndicator(MColors.primaryPurple)),
343+
);
344+
break;
345+
default:
346+
return Container(
347+
height: MediaQuery.of(context).size.height / 7,
348+
child:
349+
Center(child: progressIndicator(MColors.primaryPurple)),
350+
);
351+
}
352+
},
311353
),
312354
),
313355
],

0 commit comments

Comments
 (0)