address_search_field 3.0.3 address_search_field: ^3.0.3 copied to clipboard
An address search field which helps to autocomplete an address by a reference. It can be used to get Directions beetwen two points.
Address Search Field #
Widget builders to create 'address search widgets' which helps to autocomplete an address using a reference. They can be used to get Directions beetwen two places with optional waypoints. These widgets are made to be showed by onTap
in a TextField
with the showDialog
function.
It uses HTTP, Location, Google Maps for Flutter plugins. (This last plugin is to use extended objects that can be usable with GoogleMap
Widget).
Getting Started #
To use this plugin, add address_search_field
as a dependency in your pubspec.yaml file. For example:
dependencies:
address_search_field: ^3.0.3
Permissions #
Android #
On Android you'll need to add the internet permission to your Android Manifest file (located under android/app/src/main). To do so add next lines as direct child of the <manifest>
tag:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
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';
GeoMethods #
GeoMethods(
googleApiKey: String,
language: String,
countryCode: String,
country: String,
city: String,
mode: String,
);
- This object makes calls to Google APIs using the parameters set. It can do requests to Google places, geocode and directions APIs.
- Language support list here.
- List of countries here.
AddressSearchBuilder #
This widget is a builder which provides of parameters and methods to create a widget that can search addresses and permits to work with them using an Address
object.
AddressSearchBuilder(
geoMethods: GeoMethods,
controller: TextEditingController,
builder: (
BuildContext context,
AsyncSnapshot<List<Address>> snapshot, {
TextEditingController controller,
Future<void> Function() searchAddress,
Future<Address> Function(Address address) getGeometry,
}) {
// building example
return AddressSearchDialog(
snapshot: snapshot,
controller: controller,
searchAddress: searchAddress,
getGeometry: getGeometry,
onDone: (address) => null,
);
},
);
AddressSearchDialog
shouldn't be used alone. It needs parameters fromAddressSearchBuilder
. The best way to use this widget is usingAddressSearchBuilder.deft
, which will just use anAddressDialogBuilder
and it's an easier implementation.
AddressSearchBuilder.deft(
geoMethods: GeoMethods,
controller: TextEditingController,
builder: AddressDialogBuilder(),
onDone: (Address address) {},
);
AddressDialogBuilder #
This builder uses parameters to customize an AddressSearchDialog
which is called from AddressSearchBuilder
.
AddressDialogBuilder(
color: Color,
backgroundColor: Color,
hintText: String,
noResultText: String,
cancelText: String,
continueText: String,
useButtons: bool,
);
RouteSearchBox #
This is a special widget with a builder which provides of three AddressSearchBuilder
to search an origin Address
, destination Address
and optionally waypoints in a List<Address>
. This widget is used to get directions from the points got by the builder's AddressSearchBuilder
s.
A completed example of how to use this widget could be found here.
RouteSearchBox(
originIsMyLocation: bool,
onOriginLoading: String,
onOriginError: String,
geoMethods: GeoMethods,
originCtrlr: TextEditingController,
destinationCtrlr: TextEditingController,
waypointCtrlr:TextEditingController,
builder: (
BuildContext context,
AddressSearchBuilder originBuilder,
AddressSearchBuilder destinationBuilder,
AddressSearchBuilder waypointBuilder, {
WaypointsManager waypointsMgr,
Future<Directions> Function() getDirections,
}) {
// building example
return TextField(
controller: originCtrlr,
onTap: () => showDialog(
context: context,
builder:
(context) =>
originBuilder.buildDefault(
builder: AddressDialogBuilder(),
onDone: (address) => null,
),
),
);
},
);
License #
MIT License