address_search_text_field 1.2.2 address_search_text_field: ^1.2.2 copied to clipboard
An address search box that gets nearby addresses by typing a reference, returns an object with place primary data. The object can also find an address using coordinates.
Address Search Text Field #
A text field that displays an address search bar that finds a location from a reference and gets nearby addresses. Selecting the desired address returns an object with the latitude, longitude, and full address of the place. It uses location, geolocator, geocoder plugins.
Getting Started #
To use this plugin, add address_search_text_field
as a dependency in your pubspec.yaml file. For example:
dependencies:
address_search_text_field: ^1.2.2
Android #
NOTE: As plugins switched to the AndroidX version of the Android Support Libraries. This means you need to make sure your Android project is also upgraded to support AndroidX. Detailed instructions can be found here.
- Add the following to your "gradle.properties" file:
android.useAndroidX=true
android.enableJetifier=true
- Make sure you set the
compileSdkVersion
in your "android/app/build.gradle" file to 28:
android {
compileSdkVersion 28
...
}
Permissions #
Android #
On Android you'll need to add either the ACCESS_COARSE_LOCATION
or the ACCESS_FINE_LOCATION
permission to your Android Manifest file (located under android/app/src/main). To do so add one of the following two lines as direct children of the <manifest>
tag:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Also you should add internet permission
<uses-permission android:name="android.permission.INTERNET"/>
iOS #
On iOS you'll need to add the NSLocationWhenInUseUsageDescription
to your Info.plist file (located under ios/Runner) in order to access the device's location. Simply open your Info.plist file and add the following:
<key>NSLocationWhenInUseUsageDescription</key>
<true/>
<key>NSLocationAlwaysUsageDescription</key>
<true/>
Usage #
Import the package:
import 'package:address_search_text_field/address_search_text_field.dart';
Implement it by creating an AddressSearchTextField variable. You can call widget function which returns a TextField Widget. It requires context, country and onDone as parameters, also can add exceptions for found addresses, InputDecoration and TextStyle for TextField.
Widget addressSearchTextField = AddressSearchTextField.widget(
context: context,
controller: controller,
decoration: InputDecoration(),
style: TextStyle(),
country: country,
exceptions: <String>[],
coordForRef: bool,
onDone: (AddressPoint value) {},
);
Parameters | Description |
---|---|
context | BuildContext (Not Null) (required) |
controller | TextEditingController (optional) |
decoration | InputDecoration (optional) |
style | TextStyle (optional) |
country | String (Not Null) (required) |
exceptions | List < String > (optional) |
coordForRef | bool (optional) |
onDone | Function(AddressPoint) (required) |
Widget addressSearchBox = AddressSearchBox(
controller: controller,
country: country,
exceptions: <String>[],
coordForRef: bool,
onDone: (AddressPoint value) {},
);
Parameters | Description |
---|---|
controller | TextEditingController (optional) |
country | String (Not Null) (required) |
exceptions | List < String > (optional) |
coordForRef | bool (optional) |
onDone | Function(AddressPoint) (required) |
At onDone function you get an AddressPoint object with confirmation if place has been found, full address and coordinates. Example
Outcomes #
onDone: (AddressPoint point) {
print(point.toString());
}
There are three possible outcomes:
- If no search has been performed then the object will have null values in its address, latitude and longitude variables.
- If a place has been found from the reference, all the variables will be initialized.
- If the desired location has not been found and the reference entered by the user is selected, there will be no latitude and longitude values and the address will be the user's reference since nothing was found.
NOTE: User usually has to tap the text field in the search bar again to find the place with its full reference
License #
MIT License