google_api_availability 2.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 99

Flutter Google Api Availability Plugin #

pub package

A Flutter plugin to check the availability of Google Play services on the current device.

BranchBuild Status
developBuild Status
masterBuild Status

Features #

  • Check the availability of Google Play services (on Android only).

Usage #

To use this plugin, add google_api_availability as a dependency in your pubspec.yaml file. For example:

dependencies:
  google_api_availability: ^2.0.4

NOTE: There's a known issue with integrating plugins that use Swift into a Flutter project created with the Objective-C template. See issue Flutter#16049 for help on integration.

API #

GoogleApiAvailability #

To check the availability of Google Play services on the current device, you can use the checkGooglePlayServicesAvailability method. This could be helpful to provide a more friendly experience to users in case an user-action is required to enable support for Google Play services (More information can be found here).

import `package:google_api_availability/google_api_availability.dart`;

GooglePlayServicesAvailability availability = await GoogleApiAvailability().checkGooglePlayServicesAvailability();

If you want to show a dialog by the Android system with more information and show a possible fix to the user you can do:

import `package:google_api_availability/google_api_availability.dart`;

GooglePlayServicesAvailability availability = await GoogleApiAvailability().checkGooglePlayServicesAvailability(true);

Note that on iOS this will always return false!

See also the example project for a complete implementation.

Issues #

Please file any issues, bugs or feature request as an issue on our GitHub page.

Want to contribute #

If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature), please carefully review our contribution guide and send us your pull request.

Author #

This Google Api Availability plugin for Flutter is developed by Baseflow. You can contact us at hello@baseflow.com

2.0.4 #

  • Android: Depend on GMS base instead of location;
  • Android: Make a clear separation between Application lifecycle and methodchannel implementation;
  • Android: Added end-to-end tests.

2.0.3+hotfix.1 #

  • Android: Fix a possible null reference when the plugin is called from an App running in the background.

2.0.3 #

  • Android: Migrate to FlutterPlugin Android API (better support for Add-to-App);

2.0.2 #

  • Migrate to AndroidX
  • Synchonize Gradle and Gradle Wrapper versions with Flutter stable (1.12.13+hotfix.5)

2.0.1 #

  • No longer rely on the Activity object when this plugin is instantiated.

2.0.0 #

  • Move from swift to Objective-C and from Kotlin to Java

1.0.6+1 #

  • Revert the breaking 1.0.6 update. 1.0.6 was known to be breaking and should have incremented the major version number instead of the minor. This revert is in and of itself breaking for anyone that has already migrated however. Anyone who has already migrated their app to AndroidX should immediately update to 2.0.0 instead. That's the correctly versioned new push of 1.0.6.

1.0.6 #

  • BAD. This was a breaking change that was incorrectly published on a minor version upgrade, should never have happened. Reverted by 1.0.6+1.

"Breaking change. Migrate from the deprecated original Android Support Library to AndroidX. This shouldn't result in any functional changes, but it requires any Android apps using this plugin to also migrate if they're using the original support library."

1.0.5 #

  • BAD. This was a breaking change that was incorrectly published on a minor version upgrade, should never have happened. Reverted by 1.0.6+1.

"Breaking change. Migrate from the deprecated original Android Support Library to AndroidX. This shouldn't result in any functional changes, but it requires any Android apps using this plugin to also migrate if they're using the original support library."

1.0.4 #

  • Update used Kotlin and Gradle versions.

1.0.3 #

  • Bug fix that is introduced due to breaking changes in Flutter version 0.9.6.

1.0.2 #

  • Add additional iOS configuration to make sure it compiles correcty using Swift 4.1

1.0.1 #

  • Add iOS implementation that returns false

1.0.0 #

  • Initial release

example/lib/main.dart

import 'dart:async';

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

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

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

class _MyAppState extends State<MyApp> {
  GooglePlayServicesAvailability _playStoreAvailability =
      GooglePlayServicesAvailability.unknown;

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> checkPlayServices([bool showDialog = false]) async {
    GooglePlayServicesAvailability playStoreAvailability;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      playStoreAvailability = await GoogleApiAvailability.instance
          .checkGooglePlayServicesAvailability(showDialog);
    } on PlatformException {
      playStoreAvailability = GooglePlayServicesAvailability.unknown;
    }

    // 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(() {
      _playStoreAvailability = playStoreAvailability;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: ListView(
            children: <Widget>[
              MaterialButton(
                onPressed: () => checkPlayServices(),
                child: const Text('Get PlayServices availability'),
                color: Colors.red,
              ),
              MaterialButton(
                onPressed: () => checkPlayServices(true),
                child:
                    const Text('Get PlayServices availability with fix dialog'),
                color: Colors.redAccent,
              ),
              Center(
                  child: Text(
                      'Google Play Store status: ${_playStoreAvailability.toString().split('.').last}\n')),
            ],
          )),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  google_api_availability: ^2.0.4

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:google_api_availability/google_api_availability.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
98
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
99
Learn more about scoring.

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

  • Dart: 2.8.2
  • pana: 0.13.8-dev
  • Flutter: 1.17.1

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
e2e ^0.4.0
flutter_driver
flutter_test
pedantic 1.8.0+1