flutter_google_places_sdk 0.1.0+3

  • Readme
  • Changelog
  • Example
  • Installing
  • 67

flutter_google_places_sdk #

pub package

A Flutter plugin for google places sdk that uses the native libraries on each platform

Note: Currently only support Android

Usage #

To use this plugin, add flutter_google_places_sdk as a dependency in your pubspec.yaml file.

Example #

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

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      body: Center(
        child: RaisedButton(
          onPressed: () async {
            final places = FlutterGooglePlacesSdk('my-key');
            final predictions =
                await places.findAutocompletePredictions('Tel Aviv');
            print('Result: $predictions');
          },
          child: Text('Predict and print to console'),
        ),
      ),
    ),
  ));
}

0.1.0+3 #

  • Exposing Powered by google assets from platform interface

0.1.0+2 #

  • Updated platform interface dependency to 0.1.0+1
  • Added PoweredByGoogle image to the example

0.1.0+1 #

  • Changed to a more elaborated description in pubspec.yaml

0.1.0 #

  • Initial Open Source release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_google_places_sdk/flutter_google_places_sdk.dart';
import 'package:flutter_google_places_sdk_platform_interface/flutter_google_places_sdk_platform_interface.dart';

const title = 'Flutter Google Places SDK Example';

// note: do NOT store your api key in here or in the code at all.
// use an external source such as file or firebase remote config
const API_KEY = 'my-key';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: title,
      theme: ThemeData(
        primaryColor: Colors.blueAccent,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String _lasText;

  FlutterGooglePlacesSdk _places;

  bool _looking = false;
  dynamic _err;

  List<AutocompletePrediction> _predictions;

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

    _places = FlutterGooglePlacesSdk(API_KEY);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text(title)),
      body: Padding(
        padding: EdgeInsets.all(30),
        child: ListView(children: [
          TextFormField(
            onChanged: _onTextChanged,
          ),
          RaisedButton(
            onPressed: _looking == true ? null : _predict,
            child: const Text('Predict'),
          ),
          Image(image: FlutterGooglePlacesSdkPlatform.ASSET_POWERED_BY_GOOGLE_ON_WHITE),
          _buildErrorWidget(),
          Column(
            mainAxisSize: MainAxisSize.min,
            children: (_predictions ?? [])
                .map(_buildPredictionItem)
                .toList(growable: false),
          )
        ]),
      ),
    );
  }

  void _onTextChanged(String value) {
    _lasText = value;
  }

  void _predict() async {
    if (_looking) {
      return;
    }

    setState(() {
      _looking = true;
      _err = null;
    });

    try {
      final result = await _places
          .findAutocompletePredictions(_lasText, countries: ['il']);

      setState(() {
        _predictions = result.predictions;
        _looking = false;
      });
    } catch (err) {
      setState(() {
        _err = err;
        _looking = false;
      });
    }
  }

  Widget _buildPredictionItem(AutocompletePrediction item) {
    return Column(children: [
      Text(item.fullText),
      Text(item.primaryText + ' - ' + item.secondaryText),
      const Divider(thickness: 2),
    ]);
  }

  Widget _buildErrorWidget() {
    final theme = Theme.of(context);
    final errorText = _err == null ? '' : _err.toString();
    return Text(errorText,
        style: theme.textTheme.caption.copyWith(color: theme.errorColor));
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_google_places_sdk: ^0.1.0+3

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_google_places_sdk/flutter_google_places_sdk.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
34
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]
67
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:flutter_google_places_sdk/flutter_google_places_sdk.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:flutter_google_places_sdk/flutter_google_places_sdk.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:flutter_google_places_sdk/flutter_google_places_sdk.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:flutter_google_places_sdk/flutter_google_places_sdk.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • flutter_google_places_sdk that is a package requiring null.

Health issues and suggestions

Document public APIs. (-1 points)

11 out of 11 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.7.0 <3.0.0
flutter 0.0.0
flutter_google_places_sdk_platform_interface ^0.1.0+1 0.1.0+1
flutter_plugin_android_lifecycle ^1.0.8 1.0.8
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
plugin_platform_interface 1.0.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test
mockito ^4.1.1