flutter_google_places_autocomplete 0.0.4

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 89

flutter_google_places_autocomplete

Google places autocomplete widgets for flutter.

Getting Started

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

# pubspec.yaml

dependencies:
  flutter:
    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.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

example/lib/main.dart

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),
    routes: {
      "/": (_) => new MyApp(),
      "/search": (_) => new CustomSearchScaffold()
    },
  ));
}

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

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

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

  @override
  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) {
                      homeScaffoldKey.currentState.showSnackBar(
                          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: () {
              Navigator.of(context).pushNamed("/search");
            },
          ),
        ],
      )),
    );
  }
}

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;

    scaffold.showSnackBar(
        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 {
  CustomSearchScaffold()
      : super(
            apiKey: kGoogleApiKey,
            language: "en",
            components: [new Component(Component.country, "uk")]);

  @override
  _CustomSearchScaffoldState createState() => new _CustomSearchScaffoldState();
}

class _CustomSearchScaffoldState extends GooglePlacesAutocompleteState {
  @override
  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);
  }

  @override
  void onResponseError(PlacesAutocompleteResponse response) {
    super.onResponseError(response);
    searchScaffoldKey.currentState
        .showSnackBar(new SnackBar(content: new Text(response.errorMessage)));
  }

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

1. Depend on it

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


dependencies:
  flutter_google_places_autocomplete: "^0.0.4"

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support packages 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';
        
Version Uploaded Documentation Archive
0.0.4 Feb 2, 2018 Go to the documentation of flutter_google_places_autocomplete 0.0.4 Download flutter_google_places_autocomplete 0.0.4 archive
0.0.3+1 Jan 7, 2018 Go to the documentation of flutter_google_places_autocomplete 0.0.3+1 Download flutter_google_places_autocomplete 0.0.3+1 archive
0.0.3 Dec 21, 2017 Go to the documentation of flutter_google_places_autocomplete 0.0.3 Download flutter_google_places_autocomplete 0.0.3 archive
0.0.2 Dec 21, 2017 Go to the documentation of flutter_google_places_autocomplete 0.0.2 Download flutter_google_places_autocomplete 0.0.2 archive
0.0.1 Sep 6, 2017 Go to the documentation of flutter_google_places_autocomplete 0.0.1 Download flutter_google_places_autocomplete 0.0.1 archive

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1
  • Flutter: 0.0.22

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
78 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
89

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0
flutter 0.0.0
google_maps_webservice ^0.0.3 0.0.3
Transitive dependencies
async 2.0.3
charcode 1.1.1
collection 1.14.5
http 0.11.3+16
http_parser 3.1.1
meta 1.1.1 1.1.2
path 1.5.1
sky_engine 0.0.99
source_span 1.4.0
string_scanner 1.0.2
typed_data 1.1.4 1.1.5
vector_math 2.0.5
Dev dependencies
test ^0.12.0