Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

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, google maps for flutter plugins. (this last plugin is to use extended objects that can be usable with googlemap widget).

address search

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.5

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. example:

geomethods geomethods;
texteditingcontroller controller;

addresssearchbuilder(
  geomethods: geomethods,
  controller: controller,
  builder: (
    buildcontext context,
    asyncsnapshot<list<address>> snapshot, {
    texteditingcontroller controller,
    future<void> function() searchaddress,
    future<address> function(address address) getgeometry,
  }) {
    return addresssearchdialog(
      snapshot: snapshot,
      controller: controller,
      searchaddress: searchaddress,
      getgeometry: getgeometry,
      ondone: (address address) => null,
    );
  },
);

addresssearchdialog shouldn’t be used alone. it needs parameters from addresssearchbuilder. the best way to use this widget is using addresssearchbuilder.deft, which will just use an addressdialogbuilder and it’s an easier implementation. example:

geomethods geomethods;
texteditingcontroller controller;

addresssearchbuilder.deft(
  geomethods: geomethods,
  controller: controller,
  builder: addressdialogbuilder(),
  ondone: (address address) => null,
);

addressdialogbuilder

this builder uses parameters to customize an addresssearchdialog which is called from addresssearchbuilder. example:

addressdialogbuilder(
  color: color,
  backgroundcolor: color,
  hinttext: string,
  noresulttext: string,
  canceltext: string,
  continuetext: string,
  usebuttons: bool,
);

addresslocator

this widget is a simple way to set an initial address reference in a texteditingcontroller when the addresssearchbuilder is not created by a routesearchbox. locator param provides a relocate function to do it and get an address. example:

geomethods geomethods;
texteditingcontroller controller;
coords initialcoords;
address initialaddress;

addresslocator(
  geomethods: geomethods,
  controller: controller,
  locator: (relocate) async => controller.text.isempty
      ? initialaddress.update(await relocate(initialcoords))
      : null,
  child: textfield(
    ontap: () => addresssearchbuilder.deft(
      geomethods: geomethods,
      controller: controller,
      builder: addressdialogbuilder(),
      ondone: (address address) {},
    ),
  ),
);

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 addresssearchbuilders.
a completed example of how to use this widget could be found here. example:

geomethods geomethods;
texteditingcontroller originctrl;
texteditingcontroller destctrl;
coords initialcoords;

routesearchbox(
  geomethods: geomethods,
  originctrl: originctrl,
  destinationctrl: destctrl,
  builder: (
    buildcontext context,
    addresssearchbuilder originbuilder,
    addresssearchbuilder destinationbuilder, {
    future<directions> function() getdirections,
    void function(addressid addrid, coords coords) relocate,
    addresssearchbuilder waypointbuilder,
    waypointsmanager waypointsmgr,
  }) {
    if(controller.text.isempty) relocate(addressid.origin, initialcoords);
    return column(
      children: [
        textfield(
          controller: originctrl,
          ontap: () => showdialog(
            context: context,
            builder:
                (context) => 
                    originbuilder.builddefault(
              builder: addressdialogbuilder(),
              ondone: (address address) => null,
            ),
          ),
        ),
        textfield(
          controller: destctrl,
          ontap: () => showdialog(
            context: context,
            builder:
                (context) => 
                    destinationbuilder.builddefault(
              builder: addressdialogbuilder(),
              ondone: (address address) => null,
            ),
          ),
        ),
      ],
    );
  },
);

Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Top