flutter_google_places 0.0.1

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

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: <last-version>

const kGoogleApiKey = "API_KEY";

Prediction p = await PlacesAutocomplete.show(
                          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:google_maps_webservice/places.dart';
import 'package:flutter_google_places/flutter_google_places.dart';
import 'package:flutter/material.dart';

const kGoogleApiKey = "API_KEY";

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

main() {
  runApp(MaterialApp(
    title: "My App",
    theme: 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: {"/": (_) => MyApp(), "/search": (_) => CustomSearchScaffold()},
  ));
}

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

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

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

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

                displayPrediction(p, homeScaffoldKey.currentState);
              },
              child: Text("Search places")),
          RaisedButton(
            child: 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(SnackBar(content: Text("${p.description} - $lat/$lng")));
  }
}

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

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

class _CustomSearchScaffoldState extends PlacesAutocompleteState {
  @override
  Widget build(BuildContext context) {
    final appBar = AppBar(title: AppBarPlacesAutoCompleteTextField());
    final body = PlacesAutocompleteResult(onTap: (p) {
      displayPrediction(p, searchScaffoldKey.currentState);
    });
    return Scaffold(key: searchScaffoldKey, appBar: appBar, body: body);
  }

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

  @override
  void onResponse(PlacesAutocompleteResponse response) {
    super.onResponse(response);
    if (response != null && response.predictions.isNotEmpty) {
      searchScaffoldKey.currentState.showSnackBar(
        SnackBar(content: 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: ^0.0.1

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/flutter_google_places.dart';
  
Version Uploaded Documentation Archive
0.0.1 Sep 22, 2018 Go to the documentation of flutter_google_places 0.0.1 Download flutter_google_places 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
77
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
87
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.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

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

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