An address search field which helps to autocomplete an address by a reference

Overview

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

Getting Started

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

dependencies:
  address_search_field: ^4.0.0

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>NSLocationWhenInUseUsageDescriptionkey>
<string>Permission to get your locationstring>

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 Get API key.
  • Language support list here.
  • List of countries here.

Example:

final geoMethods = GeoMethods(
  googleApiKey: 'GOOGLE_API_KEY',
  language: 'en',
  countryCode: 'us',
  countryCodes: ['us', 'es', 'co'],
  country: 'United States',
  city: 'New York',
);
    
geoMethods.autocompletePlace(query: 'place streets or reference'); // It will search in unite states, espain and colombia. It just can filter up to 5 countries.
geoMethods.geoLocatePlace(coords: Coords(0.10, 0.10));
geoMethods.getPlaceGeometry(reference: 'place streets', placeId: 'ajFDN3662fNsa4hhs42FAjeb5n');
geoMethods.getDirections(origin: Address(coords: Coords(0.10, 0.10)), destination: Address(coords: Coords(0.10, 0.10))); // It needs a specific region, it will search in unite states.

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.deft(
  geoMethods: geoMethods,
  controller: controller,
  builder: AddressDialogBuilder(),
  onDone: (Address address) => null,
);

AddressSearchDialog.deft creates the widget showed on post's top. If you don't add .deft at end you can create your own widget to work with the addresses information.

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 MyCustomWidget(
      snapshot: snapshot,
      controller: controller,
      searchAddress: searchAddress,
      getGeometry: getGeometry,
      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 {
    if(controller.text.isEmpty) 
      initialAddress.update(await relocate(initialCoords)) // by initial coordinates you can get an address reference to be predefined in the widget and save all the address data in a variable.
  },
  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

. This widget is used to get directions from the points got by the builder's AddressSearchBuilders. relocate function permits to set an initial position as origin or destination from an initial coordinates parameter. 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(originCtrl.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,
            ),
          ),
        ),
      ],
    );
  },
);

License

MIT License

Contact

You can contact me if you have problems or ideas. Hablo español e inglés.

[email protected]

Comments
  • Xcode ios GeneratedPluginRegistrant.m  address_search_field' Module not found

    Xcode ios GeneratedPluginRegistrant.m address_search_field' Module not found

    Hello, I use address_search_field in a project, when I build the application on xcode I get this error Module 'address_search_field' not found

    I did this command but it doesn't work

    1. cd ios
    2. rm -rf Pods/ Podfile.lock
    3. pod install
    4. flutter clean
    5. flutter pub get
    Capture d’écran 2022-02-24 à 17 07 02
    opened by FrancisKOUAHO 6
  • The method 'AddressSearchField' isn't defined.

    The method 'AddressSearchField' isn't defined.

    Hi, i'm having a problem with this module

        lib/Screens/Delivery/widget/map.dart:1045:58: Error: **'AddressPoint' isn't a type.**
                                    (BuildContext dialogContext, AddressPoint point) {
                                                                 ^^^^^^^^^^^^
        lib/Screens/Delivery/widget/map.dart:1010:30: Error: **The method 'AddressSearchField' isn't defined for the class '_MapedState'.**
         - '_MapedState' is from 'package:bellava/Screens/Delivery/widget/map.dart' ('lib/Screens/Delivery/widget/map.dart').
        Try correcting the name to the name of an existing method, or defining a method named 'AddressSearchField'.
                              child: AddressSearchField(
    

    It happens when I try to do the flutter build ios It would be really helpful for me if u can give me any advice

    opened by galopianciola 6
  •  'geoMethods != null': is not true.

    'geoMethods != null': is not true.

    Trying out the example code but getting this error, although declared it.

    final geoMethods = GeoMethods( googleApiKey: 'GOOGLE_API_KEY', language: 'es-419', country: 'be', countryCodes: [ 'be', ], );

    opened by cedricve 4
  • Execution failed for task ':address_search_field:compileDebugKotlin'.

    Execution failed for task ':address_search_field:compileDebugKotlin'.

    Hi!

    when I launch the app get this error:

    e: /flutter/.pub-cache/hosted/pub.dartlang.org/address_search_field-1.4.1/android/src/main/kotlin/dev/jostech/address_search_field/AddressSearchFieldPlugin.kt: (13, 14): Redeclaration: AddressSearchFieldPlugin e: /flutter/.pub-cache/hosted/pub.dartlang.org/address_search_field-1.4.2/android/src/main/kotlin/dev/jostech/address_search_field/AddressSearchFieldPlugin.kt: (13, 14): Redeclaration: AddressSearchFieldPlugin

    FAILURE: Build failed with an exception.

    • What went wrong: Execution failed for task ':address_search_field:compileDebugKotlin'.
    opened by papamon0 2
  • Null check operator used on a null value

    Null check operator used on a null value

    Error in route_notifier.dart . Code:

    1. Future setLocation(AddressId addressId, Address address) async { if (addressId == AddressId.origin) { _origin = address; _originController.text = address.reference!; // here is the error. } else if (addressId == AddressId.destination) { _destination = address; _destinationController.text = address.reference!; } else if (addressId == AddressId.waypoint) { addWaypoint(address); } notifyListeners(); }

    setLocation(addressId, newAddress);//error

    Kindly solve ASAP.

    opened by Sarat-1997 1
  • Can we make city parameter for GeoMethods optional?

    Can we make city parameter for GeoMethods optional?

    When searching for an address, the city is not always available. can we make city parameter optional? At the moment, the workaround is to pass an empty string. It works, but a little ugly.

    opened by ShaneZhengNZ 1
  • Execution failed for task ':address_search_field:verifyReleaseResources'.

    Execution failed for task ':address_search_field:verifyReleaseResources'.

    Hi, I'm working to app and add this dependence. it's worked well but from updated flutter i can't generated a apk.

    When generated apk flutter show me this: You are building a fat APK that includes binaries for android-arm, android-arm64, android-x64. If you are deploying the app to the Play Store, it's recommended to use app bundles or split the APK to reduce the APK size. To generate an app bundle, run: flutter build appbundle --target-platform android-arm,android-arm64,android-x64 Learn more on: https://developer.android.com/guide/app-bundle To split the APKs per ABI, run: flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi Learn more on: https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split

    FAILURE: Build failed with an exception.

    • What went wrong: Execution failed for task ':address_search_field:verifyReleaseResources'.

    A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade Path '/Volumes/INFO/Beux/client_app/build/flutter_plugin_android_lifecycle/intermediates/compiled_local_resources/release/out' is not a readable directory.

    • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

    • Get more help at https://help.gradle.org

    BUILD FAILED in 14s Running Gradle task 'assembleRelease'... Running Gradle task 'assembleRelease'... Done 16.0s Gradle task assembleRelease failed with exit code 1

    flutter doctor: Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 1.22.5, on Mac OS X 10.15.7 19H114 darwin-x64, locale en-CO)

    [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3) [✓] Xcode - develop for iOS and macOS (Xcode 12.3) [✓] Android Studio (version 4.0) [✓] VS Code (version 1.52.1) [!] Connected device ! No devices available

    ! Doctor found issues in 1 category.

    opened by bryanus1 1
  • Can't close the box

    Can't close the box

    Inside the function executed on field "onDone", must be a way to close the dialog, in the example it use Navigator.of(context).pop() but this close the hole screen not the dialog, actually the dialog still opened in the previous screen.

    opened by aglpy 1
  • plugin v1 is completely discontinued

    plugin v1 is completely discontinued

    [2.0.0]

    • Everything is new, excepting the plugin context. See README.

    [1.4.2]

    • Add explicit dialog context like a parameter in the onDone function.

    [1.4.1]

    • Fix possible bug from useless conditional.

    [1.4.0]

    • Remake of AddressSearchTextField Plugin due to the update of Flutter 1.17 and Dart 2.8
    • LocationService class is now an async static function called initLocationService
    • Updated the README.md for a better explanation of plugin.

    [1.3.5+1]

    • discontinued.

    [1.3.5]

    • The onCleaned function parameter added in AddressSearchTextField and AddressSearchBox.

    [1.3.4]

    • Limiter sufix icon in AddressSearchBox to search for an address removed.
    • The search for an address is optimized.
    • New city, hintText and noResultsText parameters added in AddressSearchTextField and AddressSearchBox.

    [1.3.3+2]

    • A bug when the user selects their reference in AddressSearchBox widget fixed.

    [1.3.3]

    • A barrierDismissible parameter added in AddressSearchTextField.
    • The onEditingComplete and onChanged internal functions in AddressSearchBox adapted to new functionalities.
    • The onDone function is no longer required.

    [1.3.2]

    • sufix icon in AddressSearchBox modified to can limit addresses requests.

    [1.3.1]

    • Limiter to search for an address removed.

    [1.3.0+1]

    • Static method widget removed from AddressSearchTextField, it's a stateless widget now.
    • AddressSearchTextField widget doesn't need context parameter.

    [1.2.2]

    • AddressPoint returns valid latitude and longitude values when found is false.
    • UI issues in AddressSearchBox fixed.

    [1.2.1]

    • Dependency in example app fixed.
    • coordForRef boolean added, if AddressSearchBox finds coordinates by a written reference but not nearby places and the user selects the reference, then those coordinates can be used.

    [1.2.0]

    • Parameter for the controller added to AddressSearchTextField
    • Private _AddressSearch widget is now public and is named AddressSearchBox, it can be used independently.
    • onDone function in AddressSearchBox can now be asynchronous and have a CircularProgressIndicator while it's running.
    • onDone function now doesn't pop the widget, you have to add the code to close it.
    • AddressPoint object has a new method to find an address from passed latitude and longitude values.

    [1.1.0]

    • Optimized
    • Class name changed to AddressSearchTextField
    • country parameter added to AddressPoint object
    • AddressPoint object only has getters for its values

    [1.0.0]

    • Static functions issue fixed.
    • result getter function removed.
    • Callback with result added.
    • parameter for TextStyle added.

    [0.1.0+1]

    • values is now named result.
    • Update documentation.

    [0.0.1]

    • First release.
    opened by JosLuna98 0
  • Error

    Error "No ProviderScope found" whenever AddressSearchDialog is closed.

    Hi,

    I'm using this plugin on a non-riverpod app and I get the error "No ProviderScope found" whenever the AddressSearchDialog is closed. I'm on the latest 5.0.2 plugin version and latest stable Flutter. For reference: I'm using Flutter Modular and Mobx.

    Is this plugin intended to be used only with Flutter Riverpod?

    opened by softnodelabs 2
Releases(v4-discontinued)
Owner
Jose Luna
I'm here to learn ༼ つ ◕_◕ ༽つ
Jose Luna
Masked text field - A flutter package for masked text field for formet your text and good UI

Masked Text Field Masked Text Field Features A package for masked text field for

Alok Dubey 7 Sep 4, 2022
This is my way to build a Tagged Search Field that display a list with suggestions while the user type.

tagged_search_field This is my way to build a Tagged Search Field that display a list with suggestions while the user type. A regular search field at

Sherly Cabrera Sánchez 0 Nov 5, 2021
A Dart package which simulates pass by reference feature

Reference Wrapper is a Dart package which simulates pass by reference feature us

null 0 Dec 19, 2021
A google browser clone which is made by using flutter and fetching the google search api for the search requests.

google_clone A new Flutter project. Project Preview Getting Started This project is a starting point for a Flutter application. A few resources to get

Priyam Soni 2 May 31, 2022
Create highly customizable, simple, and controllable autocomplete fields for Flutter.

Field Suggestion Installing Depend on it Add this to your package's pubspec.yaml file: dependencies: field_suggestion: <latest_version> Install it Y

Ismael Shakverdiev 21 Oct 18, 2022
The reference implementation of Sass, written in Dart.

A Dart implementation of Sass. Sass makes CSS fun again. Using Dart Sass From Chocolatey or Scoop (Windows) From Homebrew (macOS) Standalone From npm

Sass 3.4k Jan 5, 2023
A TypeAhead (autocomplete) widget for Flutter, where you can show suggestions to users as they type

Starlight Type Ahead FLUTTER | ANDROID, IOS, LINUX, MACOS, WEB, WINDOWS A TypeAhead (autocomplete) widget for Flutter, where you can show suggestions

Ye Myo Aung 4 Dec 15, 2021
A reference credential wallet built on Flutter and DIDKit.

Check out the Credible documentation here. Credible Credible is a native mobile wallet that supports W3C Verifiable Credentials and Decentralized Iden

Spruce Systems, Inc. 31 Nov 7, 2022
A reference app in flutter using the BLoC pattern.

flutter_dice A sample Flutter app that shows how to manage responsive state using the provider pattern. Concepts Illustrated Provider pattern Using a

CodeGrue 74 Nov 18, 2022
Github-search - Allows users to search users on github Uses flutter

Github Search Github Search is a cross-platform mobile application powered by Flutter Framework and Github API. The application was built with simplic

Saul 3 Sep 13, 2022
Starlight search bar - Starlight search bar with flutter

starlight_search_bar If you find the easiest way to search your item, this is fo

Ye Myo Aung 1 Apr 20, 2022
Plugin for address picker

address_picker A flutter plugin for pick address. (Support VietNam Only) How to add lib to your project: dependencies: .... address_picker: gi

null 2 Nov 12, 2021
🔥🚀 Flutter package to create Pin code input text field with every pixel customization possibility 🎨 with beautiful animations

Flutter PinPut From Tornike ?? ?? Flutter package to create Pin code input (OTP) text field with every pixel customization possibility ?? and beautifu

Tornike 451 Jan 2, 2023
A Flutter select form field widget. It shows a list of options in a dropdown menu.

select_form_field A Flutter select field widget. It shows a list of options in a dropdown menu. This widget extend TextField and has a similar behavio

m3uzz Soluções em TI 8 Sep 14, 2022
Detectable text field - Flutter Text widgets with detection features

detectable_text_field Text widgets with detection features. You can detect hasht

null 0 Feb 2, 2022
A Flutter package allows you to obtain your public IP address

IP Address This package allows you to obtain your public IP address and many other information about it Features You can get the public IP address of

Kab Agouda 3 Nov 30, 2022
A text field that displays text on different languages based on your selection.

translatable_text_field A text field that displays text on different languages based on your selection. Its basic idea is that you place this fields i

null 0 Mar 13, 2022
Flutter package for Android and iOS allow you to show a wide range of hyperlinks either in the input field or in an article view

Tagtly package help you to detect a lot of hyperlink text such as.. email, url, social media tags, hashtag and more either when user type in text field or when appear a text read only.

Mohamed Nasr 4 Jul 25, 2022
An E-Commerce application developed on Flutter, which helps to run the app on Android / IOS / Windows's OS / MacOS / Web Browser from a single codebase

BuySmart An E-Commerce application developed on Flutter, which helps to run the app on Android / IOS / Windows's OS / MacOS / Web Browser from a singl

Sumit Kumar 11 Oct 10, 2022