flutter_google_places_autocomplete 0.1.3

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

DEPRECATED

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

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

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,
      inputDecorationTheme: InputDecorationTheme(
          border: OutlineInputBorder(
              borderRadius: BorderRadius.all(Radius.circular(4.00))),
          contentPadding:
              EdgeInsets.symmetric(vertical: 12.50, horizontal: 10.00)),
    ),
    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")));
    }
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_google_places_autocomplete: ^0.1.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter 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.1.3 Sep 22, 2018 Go to the documentation of flutter_google_places_autocomplete 0.1.3 Download flutter_google_places_autocomplete 0.1.3 archive
0.1.2 Sep 21, 2018 Go to the documentation of flutter_google_places_autocomplete 0.1.2 Download flutter_google_places_autocomplete 0.1.2 archive
0.1.1+1 Aug 28, 2018 Go to the documentation of flutter_google_places_autocomplete 0.1.1+1 Download flutter_google_places_autocomplete 0.1.1+1 archive
0.1.1 Aug 19, 2018 Go to the documentation of flutter_google_places_autocomplete 0.1.1 Download flutter_google_places_autocomplete 0.1.1 archive
0.1.0 Aug 1, 2018 Go to the documentation of flutter_google_places_autocomplete 0.1.0 Download flutter_google_places_autocomplete 0.1.0 archive
0.0.5 Jun 21, 2018 Go to the documentation of flutter_google_places_autocomplete 0.0.5 Download flutter_google_places_autocomplete 0.0.5 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

All 11 versions...

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

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4
  • Flutter: 0.9.5

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

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.9
rxdart ^0.18.1 0.18.1
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.11
http 0.12.0
http_parser 3.1.3
meta 1.1.6
path 1.6.2
sky_engine 0.0.99
source_span 1.4.1
string_scanner 1.0.4
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
test ^1.3.0