address_search_field 1.4.2

Flutter Android iOS

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 Field #

A text field that displays an address search box to find a location by typing 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.

NOTE: This package was made with Flutter 1.17 and Dart 2.8, make sure you have your environment within the version range.

environment:
  sdk: ">=2.7.0 <3.0.0"
  flutter: ">=1.10.0"

Getting Started #

To use this plugin, add address_search_field as a dependency in your pubspec.yaml file. For example:

dependencies:
  address_search_field: ^1.4.2

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 have to 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>
<string>Permission to get your location</string>

Usage #

Import the package:

import 'package:address_search_field/address_search_field.dart';
  • This widget is a search box to write a reference about a place and find an address.
AddressSearchBox(
  controller: TextEditingController(),
  country: String,
  city: String,
  hintText: String,
  noResultText: String,
  exceptions: <String>[],
  coordForRef: bool,
  onDone: (BuildContext dialogContext, AddressPoint point) {},
  onCleaned: () {},
);
ParametersTypeDescription
controllerOptionalThe controller allows you to interact with the text in the field.
countryRequired, Not NullYou have to set in which country to search.
cityOptionalYou may set in which city to search.
hintTextRequired, Not NullText suggestion according to your language in the search box.
noResultsTextRequired, Not NullMessage according to your language when the search box doesn't find anything.
exceptionsOptionalResults you don't want to show.
coordForRefOptionalIt's false by default. With the value true, it will use what the user typed in the search box as a valid Address.
onDoneOptionalWhen the search stops, it gives you an AddressPoint object with confirmation if a place has been found, full address, and coordinates.
onCleanedOptionalWhen the search box is closed with an empty text field, this function is executed.
  • This widget is a TextField that displays aAddressSearchBox by tapping it. It has 3 more parameters to personalize the TextField.
AddressSearchField(
  controller: TextEditingController(),
  decoration: InputDecoration(),
  style: TextStyle(),
  barrierDismissible: bool,
  country: String,
  city: String,
  hintText: String,
  noResultsText: String,
  exceptions: <String>[],
  coordForRef: bool,
  onDone: (BuildContext dialogContext, AddressPoint point) {},
  onCleaned: () {},
);
ParametersTypeDescription
decorationOptionalThe decoration to show around the text field.
styleOptionalThe style to use for the text being edited.
barrierDismissibleOptionalIt's true by default. With the value false, it won't close the search box when you tap outside it.
  • When the address search is complete, you can get an AddressPoint object that provides the following values:
onDone: (BuildContext dialogContext, AddressPoint point) {
  bool found = point.found;
  String address = point.address;
  String country = point.country;
  double latitude = point.latitude;
  double longitude = point.longitude;
  Navigator.of(dialogContext).pop(); // Use it JUST in a AddressSearchField widget to close the dialog.
}

There are three possible outcomes:

  1. If no search has been performed then the object will have null values ​​in its address, latitude and longitude variables.
  2. If a place has been found from the reference, all the variables will be initialized.
  3. 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: You can also find an address by it's coordinates using await AddressPoint.fromPoint(latitude, longitude). If the address is not found, it will return null.

() async {
  AddressPoint point = await AddressPoint.fromPoint(latitude, longitude);
  if (point != null) print(point.address);
}
  • This plugin also has an async static function called initLocationService to verify and request location permissions. You can use optional callbacks when location service is not enabled or if permission is not granted.
() async => await initLocationService(
  noServiceEnabled: () {},
  noPermissionGranted: () {},
);

License #

MIT License

14
likes
90
pub points
82%
popularity

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.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

josluna1098@gmail.com

License

MIT (LICENSE)

Dependencies

flutter, geocoder, geolocator, location

More

Packages that depend on address_search_field