flutter_places_autocomplete 0.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 85

flutter_places_autocomplete_example #

A plugin that give you the access to google places api to search by geolocation and places to autocomplete.

Features #

  • Generate a list of locations based on user input and optional parameters;
  • Get Geolocation (lat, lng) from a place, based on place_id

Usage #

In order to use this plugin you need to add flutter_places_autocomplete to your pubspec.yaml file.

dependencies: 
    flutter_places_autocomplete: 0.1.0 

Geolocation #

You can get the place Geolocation by passing it's placeId. for example:

import 'package:flutter_places_autocomplete/flutter_places_autocomplete.dart';

Geolocation geolocation = await PacesAutocomplete(apikey: 'YOUR_API_KEY').getGeolocation(placeId: 'ChIJdd4hrwug2EcRmSrV3Vo6llI');

You can also retrive the the geolocation in string format lat,lng:

Geolocation geolocation = await PacesAutocomplete(apikey: 'YOUR_API_KEY').getGeolocation(placeId: 'ChIJdd4hrwug2EcRmSrV3Vo6llI');

geolocation.locationAsString;

You can also set optional parameters to the search

PropsDescription
fieldsYou can specify which fields of the search you want to bring.
sessionTokenA random string which identifies an autocomplete session for billing purposes

The Basic category includes the following fields: address_component, adr_address, formatted_address, geometry, icon, name, permanently_closed, photo, place_id, plus_code, type, url, utc_offset, vicinity

The Contact category includes the following fields: formatted_phone_number, international_phone_number, opening_hours, website

The Atmosphere category includes the following fields: price_level, rating, review, user_ratings_total

Predictions #

You can retrieve a list of possible predictions for an input. for example:

import 'package:flutter_places_autocomplete/flutter_places_autocomplete.dart';

Predictions predictions = await PacesAutocomplete(apikey: 'YOUR_API_KEY').gerPredictions(input: 'London');

It will retrieve a List<Prediction> which contains

PredictionDescription
descriptionThe human-readable name for the returned result.
place_idA textual identifier that uniquely identifies a place.
typesAn array of types that apply to this place.
termsAn array of terms identifying each section of the returned description
geolocationA geolocation object containing lat, lng for the place

You can set the following parameters:

PropsDescription
languageThe language code, indicating in which language the results should be returned
locationThe point around which you wish to retrieve place information. Must be specified as lat,lng.
typesThe types of place results to return.
strictboundsPlaces that are strictly within the region defined by location and radius

[0.2.0] #

  • Change typo of types to String
  • Improve documentation

[0.1.1] #

  • Set flutter SDK version

[0.1.0] #

  • Initial alpha release

example/lib/main.dart

import 'package:flutter_places_autocomplete/flutter_places_autocomplete.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Places Autocomplete',
      home: MyApp(),
    );
  }
}

class FlutterPlacesAutocompleteWidget extends StatefulWidget {
  FlutterPlacesAutocompleteWidget({Key key}) : super(key: key);

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

class _FlutterPlacesAutocompleteWidgetState
    extends State<FlutterPlacesAutocompleteWidget> {
  PlacesAutocomplete placesAutocomplete;
  List<Prediction> predictions;
  final searchController = TextEditingController();

  @override
  void initState() {
    placesAutocomplete =
        PlacesAutocomplete(apiKey: 'AIzaSyC-OHeGgrRHWqf3gkMWAKvd6yvJKpvv6xM');
    predictions = [];
  }

  @override
  void dispose() {
    // Clean up the controller when the widget is disposed.
    searchController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Flutter Places Autocomplete'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            TextField(
              controller: searchController,
            ),
            RaisedButton(
              onPressed: _fetchPredictions,
              child: Text(
                'Search',
                style: TextStyle(fontSize: 20),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Future<void> _fetchPredictions() async {
    setState(() async {
      predictions = await placesAutocomplete.getPreditcions(input: 'london');
    });
  }

  Widget _listView() {
    return ListView.builder(
        itemCount: predictions.length,
        itemBuilder: (BuildContext ctxt, int index) {
          return new Text(predictions[index].description);
        });
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_places_autocomplete: ^0.2.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_places_autocomplete/flutter_places_autocomplete.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
70
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
85
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-0.52 points)

61 out of 62 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
equatable ^1.0.2 1.1.1
flutter 0.0.0
http ^0.12.0+4 0.12.0+4
meta ^1.1.8 1.1.8
mockito ^4.1.1 4.1.1
Transitive dependencies
async 2.4.1
boolean_selector 2.0.0
charcode 1.1.3
collection 1.14.11 1.14.12
http_parser 3.1.4
matcher 0.12.6
path 1.6.4
pedantic 1.9.0
sky_engine 0.0.99
source_span 1.7.0
stack_trace 1.9.3
stream_channel 2.0.0
string_scanner 1.0.5
term_glyph 1.1.0
test_api 0.2.15
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test