play_games 0.3.1

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

play_games

Use Google Play Games Services on your Flutter app; this allows for signin and achievements so far, but more additions are very welcome. If you like it, give us a star and feel free to help and contribute.

Part 1: Sign In

Call the sign in method to sign in; you must check if the login was successufully.

    SigninResult result = await PlayGames.signIn();
    if (result.success) {
        await PlayGames.setPopupOptions();
        this.account = result.account;
    } else {
        this.error = result.message;
    }
    this.loading = false;

But don't think it will be that easy! Actually, GPGS signin is quite a hassle to do, but this tutorial should help you out with this nefarious task.

Reasons for failure will be specified in the error property. Otherwhise, you can access the account property to get the account.

Part 2: Achievements

You can both award achievements (unlock/increment) and show the Achievements screen in your game.

In order to unlock or increment an achievement, use the provided APIs:

  PlayGames.unlockAchievementByName(name);

This is async and you wait for the return if desired. The name is the name in your games-ids.xml file, you can also call the by id method.

Also, there is a method to display a popup with your achievements:

    PlayGames.showAchievements();

Again, this is async and returns only when the player closes the popup. So maybe you want to pause your game until that happens.

Part 3: Saved Games

Firstly, you must enable Saved Games. Go to your Google Play Console > Game Services > Select your game > Game details and toggle Saved Games option on. Then Save and publish. Beware, this cannot be later turned off.

Example of Saved Games

Secondly, in order to use the Saved Games feature, you must required explicit permission upon logging in. Thankfully, the signIn method can be configured to ask for that permission via the scopeSnapshot option, like so:

    SigninResult result = await PlayGames.signIn(scopeSnapshot: true); // allow to load/save games later

By default that option is false, so be sure to check it in. In Saved Games, a snapshot is of one save slot, that is, one representation of the game state that can be reloaded later. It is comprised of content, a blob, and metadata, a structured key-value pairs set.

You can use the methods openSnapshot and saveSnaphost to load and save game data under a given snapshotName. If your game has several slots, use several differente names for then. Otherwise, use only a single snapshotName for everything. A few points to ponder:

  • You put your save data in the content field, which is a String. You can put anything there (json, custom format, etc).
  • Metadata are also retrieved but for now only the description can be set. These metadata are useful if you are using the default save game screen provided (not support by this lib). Otherwise you can get some information from it.
  • Whenever you save a snapshot, if you intend to save again, you must reopen. You can either keep it open util the player saves the game, then save and reopen, or keep it closed, when the player saves, you open and save. Whenever you save, it is closed.

Here follows an example of the usage of the APIs from the crystap sample open-source game used to showcase this plugin:

    Future<int> fetchStartAmount() async {
        Snapshot save = await PlayGames.openSnapshot('crystap.main'); // load the existing save or create a new empty one if none exists
        if (save.content == null || save.content.trim().isEmpty) {
            return 0; // default value when there is no save
        }
        return int.parse(save.content);
    }

    Future<bool> saveAmount(int amount) async {
        bool result = await PlayGames.saveSnapshot('crystap.main', amount.toString()); // save the current state to the snapshot
        await PlayGames.openSnapshot('crystap.main'); // reopen snapshot after save
        return result;
    }

Here our data is just a single integer, that we convert to a String in order to save it within the content. Again, your save can be an arbitrarily complex JSON or anything like that. See the full Crystap game for more in-depth details on how to use the API.

There are also APIs for conflict resolution. If you want more robuts integration, check those out in the source code.

0.0.1

  • First version, very basic signin and fetch avatar.

0.1.0

  • Adding Achievements

0.2.0

  • Adding Saved Games

0.3.0

  • Adding conflict resolution to Saved Games

0.3.1

  • Fix concurrency bug when an unexpected exception was thrown

example/README.md

play_games_example

Demonstrates how to use the play_games plugin.

Getting Started

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

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


dependencies:
  play_games: ^0.3.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:play_games/play_games.dart';
  
Version Uploaded Documentation Archive
0.3.1 Jan 13, 2019 Go to the documentation of play_games 0.3.1 Download play_games 0.3.1 archive
0.3.0 Jan 5, 2019 Go to the documentation of play_games 0.3.0 Download play_games 0.3.0 archive
0.2.0 Dec 29, 2018 Go to the documentation of play_games 0.2.0 Download play_games 0.2.0 archive
0.1.0 Sep 5, 2018 Go to the documentation of play_games 0.1.0 Download play_games 0.1.0 archive
0.0.1 Aug 26, 2018 Go to the documentation of play_games 0.0.1 Download play_games 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
59
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]
79
Learn more about scoring.

We analyzed this package on Jan 15, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.10
  • Flutter: 1.1.7

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

63 out of 63 API elements (library, class, field or method) have no adequate dartdoc content. Good documentation improves code readability and discoverability through search.

Format lib/play_games.dart.

Run flutter format to format lib/play_games.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
play_games_example