google_places_picker 2.1.0+2

Flutter Android iOS

Flutter plugin for Google Places and Autocomplete.

example/lib/main.dart

import 'package:flutter/material.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();
    PluginGooglePlacePicker.initialize(
      androidApiKey: "YOUR_ANDROID_API_KEY",
      iosApiKey: "YOUR_IOS_API_KEY",
    );
  }

  _showAutocomplete() async {
    String placeName;
    var locationBias = LocationBias()
    ..northEastLat = 20.0
    ..northEastLng = 20.0
    ..southWestLat = 0.0
    ..southWestLng = 0.0;

    var locationRestriction = LocationRestriction()
      ..northEastLat = 20.0
      ..northEastLng = 20.0
      ..southWestLng = 0.0
      ..southWestLat = 0.0;

    var country = "US";

    // Platform messages may fail, so we use a try/catch PlatformException.
    var place = await PluginGooglePlacePicker.showAutocomplete(mode: PlaceAutocompleteMode.MODE_OVERLAY, countryCode: country, restriction: locationRestriction, typeFilter: TypeFilter.ESTABLISHMENT);
    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: _showAutocomplete, child: new Text("Show autocomplete")),
              new Row(
                children: <Widget>[
                  new Text("Place name: "),
                  new Text(_placeName)
                ],
              )
            ],
          ),
        ),
      ),
    );
  }
}
3
likes
80
pub points
88%
popularity

Flutter plugin for Google Places and Autocomplete.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

salexandru.tuca@gmail.com

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on google_places_picker