Skip to content

Commit

Permalink
building auto complete address
Browse files Browse the repository at this point in the history
  • Loading branch information
thenifemi committed Jul 19, 2020
1 parent 23057f7 commit 60c2f94
Showing 1 changed file with 44 additions and 8 deletions.
52 changes: 44 additions & 8 deletions lib/screens/tab_screens/checkout_screens/enterAddress.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class _EnterAddressState extends State<EnterAddress> {
Provider.of<UserDataAddressNotifier>(context, listen: false);
addressFuture = getAddress(addressNotifier);

currentLocation = getUserCurrentLocation();
currentLocation = getUserCurrentLocation(addressNotifier);

super.initState();
}
Expand Down Expand Up @@ -128,7 +128,9 @@ class _EnterAddressState extends State<EnterAddress> {
});
}

getUserCurrentLocation() async {
getUserCurrentLocation(
UserDataAddressNotifier addressNotifier,
) async {
String error;

try {
Expand All @@ -139,8 +141,20 @@ class _EnterAddressState extends State<EnterAddress> {
var addresses =
await Geocoder.local.findAddressesFromCoordinates(coordinates);
var first = addresses.first;
List<UserDataAddress> _displayResults = [];
print("${first.featureName} : ${first.addressLine}");

currentLocationAddress = first.addressLine;
Map<String, dynamic> asMap() {
return {
'addressLocation': currentLocationAddress,
};
}

addressNotifier.userDataAddressList = _displayResults;

UserDataAddress userDataAddress = UserDataAddress.fromMap(asMap());
_displayResults.add(userDataAddress);
} on PlatformException catch (e) {
if (e.code == 'PERMISSION_DENIED') {
error = 'please grant permission';
Expand Down Expand Up @@ -262,6 +276,10 @@ class _EnterAddressState extends State<EnterAddress> {
}

Widget useCurrentLocation() {
UserDataAddressNotifier addressNotifier =
Provider.of<UserDataAddressNotifier>(context);
var _addressList = addressNotifier.userDataAddressList;

return Column(
children: <Widget>[
Center(
Expand All @@ -288,7 +306,9 @@ class _EnterAddressState extends State<EnterAddress> {
? Container()
: GestureDetector(
onTap: () {
print(currentLocationAddress);
var _address = _addressList.first;
print(_address.addressLocation);
_showModalSheet(_address, true);
},
child: Container(
width: MediaQuery.of(context).size.width,
Expand Down Expand Up @@ -380,7 +400,7 @@ class _EnterAddressState extends State<EnterAddress> {

return GestureDetector(
onTap: () {
_showModalSheet(_address);
_showModalSheet(_address, false);
setState(() {
showCurrentLocation = true;
});
Expand Down Expand Up @@ -480,7 +500,7 @@ class _EnterAddressState extends State<EnterAddress> {
);
}

void _showModalSheet(UserDataAddress _address) {
void _showModalSheet(UserDataAddress _address, bool currentLocation) {
UserDataAddressNotifier addressNotifier =
Provider.of<UserDataAddressNotifier>(context, listen: false);
var addressList = addressNotifier.userDataAddressList;
Expand All @@ -504,7 +524,9 @@ class _EnterAddressState extends State<EnterAddress> {
Container(
padding: const EdgeInsets.symmetric(horizontal: 40.0),
child: Text(
"Please enter your legal name and address number",
currentLocation == false
? "Please enter your legal name, address name and number, and apt or house number"
: "Please enter your legal name and apt or house number",
style: boldFont(MColors.textDark, 16.0),
textAlign: TextAlign.center,
),
Expand Down Expand Up @@ -561,7 +583,9 @@ class _EnterAddressState extends State<EnterAddress> {
children: <Widget>[
Container(
child: Text(
"Street name and number",
currentLocation == false
? "Apt or house number and street name and number"
: "Apt or house number",
style: normalFont(MColors.textGrey, null),
),
),
Expand All @@ -577,11 +601,23 @@ class _EnterAddressState extends State<EnterAddress> {
false,
_autoValidate,
true,
TextInputType.text,
currentLocation == false
? TextInputType.text
: TextInputType.number,
null,
null,
0.50,
),
SizedBox(height: 5.0),
currentLocation == false
? Container(
child: Text(
"Please enter information in order stated above!",
style:
normalFont(MColors.primaryPurple, null),
),
)
: Container(),
],
),
SizedBox(height: 20.0),
Expand Down

0 comments on commit 60c2f94

Please sign in to comment.