Skip to content

Commit 60c2f94

Browse files
committed
building auto complete address
1 parent 23057f7 commit 60c2f94

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

lib/screens/tab_screens/checkout_screens/enterAddress.dart

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class _EnterAddressState extends State<EnterAddress> {
6262
Provider.of<UserDataAddressNotifier>(context, listen: false);
6363
addressFuture = getAddress(addressNotifier);
6464

65-
currentLocation = getUserCurrentLocation();
65+
currentLocation = getUserCurrentLocation(addressNotifier);
6666

6767
super.initState();
6868
}
@@ -128,7 +128,9 @@ class _EnterAddressState extends State<EnterAddress> {
128128
});
129129
}
130130

131-
getUserCurrentLocation() async {
131+
getUserCurrentLocation(
132+
UserDataAddressNotifier addressNotifier,
133+
) async {
132134
String error;
133135

134136
try {
@@ -139,8 +141,20 @@ class _EnterAddressState extends State<EnterAddress> {
139141
var addresses =
140142
await Geocoder.local.findAddressesFromCoordinates(coordinates);
141143
var first = addresses.first;
144+
List<UserDataAddress> _displayResults = [];
142145
print("${first.featureName} : ${first.addressLine}");
146+
143147
currentLocationAddress = first.addressLine;
148+
Map<String, dynamic> asMap() {
149+
return {
150+
'addressLocation': currentLocationAddress,
151+
};
152+
}
153+
154+
addressNotifier.userDataAddressList = _displayResults;
155+
156+
UserDataAddress userDataAddress = UserDataAddress.fromMap(asMap());
157+
_displayResults.add(userDataAddress);
144158
} on PlatformException catch (e) {
145159
if (e.code == 'PERMISSION_DENIED') {
146160
error = 'please grant permission';
@@ -262,6 +276,10 @@ class _EnterAddressState extends State<EnterAddress> {
262276
}
263277

264278
Widget useCurrentLocation() {
279+
UserDataAddressNotifier addressNotifier =
280+
Provider.of<UserDataAddressNotifier>(context);
281+
var _addressList = addressNotifier.userDataAddressList;
282+
265283
return Column(
266284
children: <Widget>[
267285
Center(
@@ -288,7 +306,9 @@ class _EnterAddressState extends State<EnterAddress> {
288306
? Container()
289307
: GestureDetector(
290308
onTap: () {
291-
print(currentLocationAddress);
309+
var _address = _addressList.first;
310+
print(_address.addressLocation);
311+
_showModalSheet(_address, true);
292312
},
293313
child: Container(
294314
width: MediaQuery.of(context).size.width,
@@ -380,7 +400,7 @@ class _EnterAddressState extends State<EnterAddress> {
380400

381401
return GestureDetector(
382402
onTap: () {
383-
_showModalSheet(_address);
403+
_showModalSheet(_address, false);
384404
setState(() {
385405
showCurrentLocation = true;
386406
});
@@ -480,7 +500,7 @@ class _EnterAddressState extends State<EnterAddress> {
480500
);
481501
}
482502

483-
void _showModalSheet(UserDataAddress _address) {
503+
void _showModalSheet(UserDataAddress _address, bool currentLocation) {
484504
UserDataAddressNotifier addressNotifier =
485505
Provider.of<UserDataAddressNotifier>(context, listen: false);
486506
var addressList = addressNotifier.userDataAddressList;
@@ -504,7 +524,9 @@ class _EnterAddressState extends State<EnterAddress> {
504524
Container(
505525
padding: const EdgeInsets.symmetric(horizontal: 40.0),
506526
child: Text(
507-
"Please enter your legal name and address number",
527+
currentLocation == false
528+
? "Please enter your legal name, address name and number, and apt or house number"
529+
: "Please enter your legal name and apt or house number",
508530
style: boldFont(MColors.textDark, 16.0),
509531
textAlign: TextAlign.center,
510532
),
@@ -561,7 +583,9 @@ class _EnterAddressState extends State<EnterAddress> {
561583
children: <Widget>[
562584
Container(
563585
child: Text(
564-
"Street name and number",
586+
currentLocation == false
587+
? "Apt or house number and street name and number"
588+
: "Apt or house number",
565589
style: normalFont(MColors.textGrey, null),
566590
),
567591
),
@@ -577,11 +601,23 @@ class _EnterAddressState extends State<EnterAddress> {
577601
false,
578602
_autoValidate,
579603
true,
580-
TextInputType.text,
604+
currentLocation == false
605+
? TextInputType.text
606+
: TextInputType.number,
581607
null,
582608
null,
583609
0.50,
584610
),
611+
SizedBox(height: 5.0),
612+
currentLocation == false
613+
? Container(
614+
child: Text(
615+
"Please enter information in order stated above!",
616+
style:
617+
normalFont(MColors.primaryPurple, null),
618+
),
619+
)
620+
: Container(),
585621
],
586622
),
587623
SizedBox(height: 20.0),

0 commit comments

Comments
 (0)