flutter_google_places_autocomplete 0.1.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 65


User https://pub.dartlang.org/packages/flutter_google_places instead

flutter_google_places_autocomplete #

pub version

Google places autocomplete widgets for flutter.

Getting Started #

For help getting started with Flutter, view our online documentation.

# pubspec.yaml

    sdk: flutter
  flutter_google_places_autocomplete: <last-version>

const kGoogleApiKey = "API_KEY";

Prediction p = await showGooglePlacesAutocomplete(
                          context: context,
                          apiKey: kGoogleApiKey,
                          mode: Mode.overlay, // Mode.fullscreen
                          language: "fr",
                          components: [new Component(Component.country, "fr")]);

The library use google_maps_webservice library which directly refer to the official documentation for google maps web service.

0.1.1 #

  • fix icons quality
  • fix input border when custom theme

0.1.0 #

  • update sdk and fix warnings

0.0.5 #

fix usage of radius

0.0.4 #

  • Open widgets to create your own UI
  • add onError callback

0.0.3 #

  • add padding for overlay on iOS

0.0.2 #

  • Update google_maps_webservice to ^0.0.3
  • fix placeholder position
  • fix keyboard clipping on overlay

0.0.1 #

Initial version


import 'dart:async';

import 'package:flutter_google_places_autocomplete/flutter_google_places_autocomplete.dart';
import 'package:flutter/material.dart';

const kGoogleApiKey = "API_KEY";

// to get places detail (lat/lng)
GoogleMapsPlaces _places = new GoogleMapsPlaces(kGoogleApiKey);

main() {
  runApp(new MaterialApp(
    title: "My App",
    theme: new ThemeData(
      accentColor: Colors.redAccent,
      inputDecorationTheme: InputDecorationTheme(
          border: OutlineInputBorder(
              borderRadius: BorderRadius.all(Radius.circular(4.00))),
              EdgeInsets.symmetric(vertical: 12.50, horizontal: 10.00)),
    routes: {
      "/": (_) => new MyApp(),
      "/search": (_) => new CustomSearchScaffold()

class MyApp extends StatefulWidget {
  _MyAppState createState() => new _MyAppState();

final homeScaffoldKey = new GlobalKey<ScaffoldState>();
final searchScaffoldKey = new GlobalKey<ScaffoldState>();

class _MyAppState extends State<MyApp> {
  Mode _mode = Mode.overlay;

  Widget build(BuildContext context) {
    return new Scaffold(
      key: homeScaffoldKey,
      appBar: new AppBar(
        title: new Text("My App"),
      body: new Center(
          child: new Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          new DropdownButton(
              value: _mode,
              items: <DropdownMenuItem<Mode>>[
                new DropdownMenuItem<Mode>(
                    child: new Text("Overlay"), value: Mode.overlay),
                new DropdownMenuItem<Mode>(
                    child: new Text("Fullscreen"), value: Mode.fullscreen),
              onChanged: (m) {
                setState(() {
                  _mode = m;
          new RaisedButton(
              onPressed: () async {
                // show input autocomplete with selected mode
                // then get the Prediction selected
                Prediction p = await showGooglePlacesAutocomplete(
                    context: context,
                    apiKey: kGoogleApiKey,
                    onError: (res) {
                          new SnackBar(content: new Text(res.errorMessage)));
                    mode: _mode,
                    language: "fr",
                    components: [new Component(Component.country, "fr")]);

                displayPrediction(p, homeScaffoldKey.currentState);
              child: new Text("Search places")),
          new RaisedButton(
            child: new Text("Custom"),
            onPressed: () {

Future<Null> displayPrediction(Prediction p, ScaffoldState scaffold) async {
  if (p != null) {
    // get detail (lat/lng)
    PlacesDetailsResponse detail = await _places.getDetailsByPlaceId(p.placeId);
    final lat = detail.result.geometry.location.lat;
    final lng = detail.result.geometry.location.lng;

        new SnackBar(content: new Text("${p.description} - $lat/$lng")));

// custom scaffold that handle search
// basically your widget need to extends [GooglePlacesAutocompleteWidget]
// and your state [GooglePlacesAutocompleteState]
class CustomSearchScaffold extends GooglePlacesAutocompleteWidget {
      : super(
            apiKey: kGoogleApiKey,
            language: "en",
            components: [new Component(Component.country, "uk")]);

  _CustomSearchScaffoldState createState() => new _CustomSearchScaffoldState();

class _CustomSearchScaffoldState extends GooglePlacesAutocompleteState {
  Widget build(BuildContext context) {
    final appBar = new AppBar(title: new AppBarPlacesAutoCompleteTextField());
    final body = new GooglePlacesAutocompleteResult(onTap: (p) {
      displayPrediction(p, searchScaffoldKey.currentState);
    return new Scaffold(key: searchScaffoldKey, appBar: appBar, body: body);

  void onResponseError(PlacesAutocompleteResponse response) {
        .showSnackBar(new SnackBar(content: new Text(response.errorMessage)));

  void onResponse(PlacesAutocompleteResponse response) {
    if (response != null && response.predictions.isNotEmpty) {
          .showSnackBar(new SnackBar(content: new Text("Got answer")));

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  flutter_google_places_autocomplete: ^0.1.3

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_google_places_autocomplete/flutter_google_places_autocomplete.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Apr 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Fix lib/src/flutter_google_places_autocomplete.dart. (-25.75 points)

Analysis of lib/src/flutter_google_places_autocomplete.dart failed with 1 error, 2 hints:

line 337 col 35: Too many positional arguments: 0 expected, but 1 found.

line 50 col 8: 'ancestorStateOfType' is deprecated and shouldn't be used. Use findAncestorStateOfType instead. This feature was deprecated after v1.12.1..

line 50 col 34: 'TypeMatcher' is deprecated and shouldn't be used. TypeMatcher has been deprecated because it is no longer used in framework(only in deprecated methods). This feature was deprecated after v1.12.1..

Maintenance issues and suggestions

No valid SDK. (-20 points)

The analysis could not detect a valid SDK that can use this package.

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (rxdart).

Package is getting outdated. (-54.25 points)

The package was last published 80 weeks ago.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
flutter 0.0.0
google_maps_webservice ^0.0.6 0.0.16
rxdart ^0.18.1 0.18.1 0.23.1
Transitive dependencies
async 2.4.1
charcode 1.1.3
collection 1.14.11 1.14.12
http 0.12.0+4
http_parser 3.1.4
meta 1.1.8
path 1.6.4
pedantic 1.9.0
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
test ^1.3.0