google_places_picker 0.0.1

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

google_places_picker

Google Place Picker and Autocomplete for Flutter

Getting Started

Setting up

  1. Go to your AndroidManifest.xml at android/app/src/main and add the following in between the application opening and closing tag, replacing YOUR_API_KEY with your api key, which you can get from the Google Developer Console:
<meta-data
      android:name="com.google.android.geo.API_KEY"
      android:value="YOUR_API_KEY"/>
  1. Go to AppDelegate.m/.swift in ios/Runner, and in the didFinishLaunchingWithOptions method add the following lines:
  • Swift

GMSPlacesClient.provideApiKey("YOUR_API_KEY")
GMSSServices.provideApiKey("YOUR_API_KEY")
  • Objective-C
[GMSPlacesClient provideApiKey:@"YOUR_API_KEY"];
[GMSServices provideApiKey:@"YOUR_API_KEY"];

Usage

You can use the plugin via the showPlacePicker and showAutocomplete methods. The showAutocomplete method takes a PlaceAutocompleteMode paramater to know whether to display the fullscreen or the overlay control on Android (it has no effect on iOS). Both methods return a Place object with the following properties:

  • name
  • id
  • address
  • latitude
  • longitude

[0.0.1] - TODO: Add release date.

  • TODO: Describe initial release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_places_picker/google_places_picker.dart';


void main() => runApp(new MyApp());

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

class _MyAppState extends State<MyApp> {
  String _placeName = 'Unknown';

  @override
  initState() {
    super.initState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  _showPlacePicker() async {
    String placeName;
    // Platform messages may fail, so we use a try/catch PlatformException.
    var place = await PluginGooglePlacePicker.showPlacePicker();
    placeName = place.name;


    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted)
      return;

    setState(() {
      _placeName = placeName;
    });
  }

  _showAutocomplete() async {
    String placeName;
    // Platform messages may fail, so we use a try/catch PlatformException.
    var place = await PluginGooglePlacePicker.showAutocomplete(PlaceAutocompleteMode.MODE_OVERLAY);
    placeName = place.name;


    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted)
      return;

    setState(() {
      _placeName = placeName;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Place picker example app'),
        ),
        body: new Center(
          child: new Column(
            children: <Widget>[
              new FlatButton(onPressed: _showPlacePicker, child: new Text("Show place picker")),
              new FlatButton(onPressed: _showAutocomplete, child: new Text("Show autocomplete")),
              new Row(
                children: <Widget>[
                  new Text("Place name: "),
                  new Text(_placeName)
                ],
              )
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  google_places_picker: ^0.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or 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:google_places_picker/google_places_picker.dart';
  
Version Uploaded Documentation Archive
0.0.6 Sep 21, 2018 Go to the documentation of google_places_picker 0.0.6 Download google_places_picker 0.0.6 archive
0.0.5 Sep 3, 2018 Go to the documentation of google_places_picker 0.0.5 Download google_places_picker 0.0.5 archive
0.0.4 May 20, 2018 Go to the documentation of google_places_picker 0.0.4 Download google_places_picker 0.0.4 archive
0.0.3 May 20, 2018 Go to the documentation of google_places_picker 0.0.3 Download google_places_picker 0.0.3 archive
0.0.2 May 19, 2018 Go to the documentation of google_places_picker 0.0.2 Download google_places_picker 0.0.2 archive
0.0.1 May 19, 2018 Go to the documentation of google_places_picker 0.0.1 Download google_places_picker 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
80
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
40
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <2.0.0