autocomplete_google_places_widget 0.0.1 copy "autocomplete_google_places_widget: ^0.0.1" to clipboard
autocomplete_google_places_widget: ^0.0.1 copied to clipboard

A wrapper around Flutter's default Autocomplete widget that leverages the Google Places API to provide real-time place suggestions as users type

A wrapper around Flutter’s default Autocomplete widget that leverages the Google Places API to provide real-time place suggestions as users type. Package Preview

Features #

  • 🎨 Highly Customizable: Offers extensive customization options to fit your specific needs.
  • 🕒 History Support: Includes history support for quick access to previous search results.
  • 💳 Session Tokens: Uses session tokens to group user queries in a single session ensuring efficient billing.
  • Debounce: Implements a debounce mechanism to reduce the frequency of API calls.

Getting started #

Import the package in your Dart file.

import 'package:autocomplete_google_places_widget/autocomplete_google_places_widget.dart';

Add your Google API key in the GPlacesAutoComplete widget.

GPlacesAutoComplete(
            googleAPIKey: _yourGoogleAPIKey,
            ...
          )

And you are good to go!

Usage #

The GPlacesAutoComplete widget has several parameters that you can use.

  /// The Google API key to use for the Places API.
  final String googleAPIKey;

  /// A callback that is called when the user selects an option.
  final void Function(Prediction)? onOptionSelected;

  /// A builder for the options view.
  final Widget Function(
      BuildContext context,
      AutocompleteOnSelected<Prediction> onSelected,
      Iterable<Prediction> options)? menuBuilder;

  /// A builder for a single option view in the menu.
  final Widget Function(BuildContext context, int index, Prediction prediction)?
      menuOptionBuilder;

  /// The time (in milliseconds) to wait after the user stops typing
  /// to make the API request.
  final int debounceTime;

  /// A builder for the field decoration. If not provided, a default
  /// decoration will be used. [isSearching] is true when the field is
  /// currently searching for options, and [isAPIException] is true when
  /// an error occurred while searching for options.
  final InputDecoration Function(bool isSearching, bool isAPIException)?
      fieldDecorationBuilder;

  /// The countries to restrict the search to (two-character region code).
  final List<String>? countries;

  /// The maximum height of the options menu.
  final double optionsMaxHeight;

  /// The maximum width of the options menu.
  final double? optionsMaxWidth;

  /// The color of the menu.
  final Color? menuColor;

  /// The elevation of the menu.
  final double menuElevation;

  /// The shape of the menu.
  final double menuBorderRadius;

  /// If true, the menu option will be dense.
  final bool denseMenuOption;

  /// If true, the prediction history will be saved in shared preferences
  /// and will be displayed in the options menu when the current query is empty
  final bool enableHistory;

  /// If True, The prediction saved will contain only the `placeId`, `description`, and `LatLng` (if available)
  final bool liteModeHistory;

Feedback #

Please feel free to give me any feedback helping support this package!

3
likes
0
pub points
22%
popularity

Publisher

verified publisherdhia.tech

A wrapper around Flutter's default Autocomplete widget that leverages the Google Places API to provide real-time place suggestions as users type

Repository (GitHub)
View/report issues

Topics

#autocomplete #google-places

License

unknown (license)

Dependencies

dio, flutter, shared_preferences, uuid

More

Packages that depend on autocomplete_google_places_widget