firebase_game_services 2.2.0 copy "firebase_game_services: ^2.2.0" to clipboard
firebase_game_services: ^2.2.0 copied to clipboard

A Flutter package, linking Google's Play Games and Apple's Game Center with Firebase.

Firebase Game Services #

Pub

Dart package linking Google's Play Games and Apple's Game Center with Firebase.


Setup #

Apple Setup

  1. Firebase iOS Setup.
  2. Authenticate Using Game Center.

Google Setup

  1. Firebase Android Setup.
  2. Authenticate Using Google Play Games Services on Android.

If you continue to encounter difficulties, kindly refer to the following discussion for further assistance: Troubleshooting Guide.

Minimum requirements

Android minSdkVersion >=19 iOS >=12.0 macOS >=12.0


Usage #

Sign in

Call this before making any other action.

await FirebaseGameServices.instance.signIn();

Save Game Data to Firebase

This package works in harmony with the Firebase stack. You can utilize both Cloud Firestore and/or Realtime Database for storing, syncing, and querying data - whatever suits your project best.

Firestore Example

This example sets a value of myValue in a Firebase Firestore document with the current users ID as the document ID inside of a defined collection.

    final FirebaseFirestore firestore = FirebaseFirestore.instance;
    final FirebaseAuth currentUser = FirebaseAuth.instance.currentUser;

    try {
        if (currentUser != null) {
        if (myValue == null || myValue.isEmpty) {
            throw Exception('myValue cannot be null or empty');
        }
        
        await firestore.collection("my-collection").doc(currentUser.uid).update({
            "my-field": myValue,
            });
        } else {
        throw Exception('User is not signed in');
        }
    } catch (e) {
        debugPrint('Error: $e');
    }

For static storage, I'd recommend using Cloud Storage or PocketBase.

Of course you can also use your own backend.

Show all leaderboards

Shows all leaderboards.

await FirebaseGameServices.instance.showAllLeaderboards();

Show single leaderboard

Shows a single leaderboard.

await FirebaseGameServices.instance.showSingleLeaderboard(iOSLeaderboardID: 'ios_leaderboard_id', androidLeaderboardID: 'android_leaderboard_id');

Submit score

To submit a Score to specific leaderboard.
-The Score class takes three parameters:
-androidLeaderboardID: the leader board id that you want to send the score for in case of android.
-iOSLeaderboardID the leader board id that you want to send the score for in case of iOS.
-value the score.

await FirebaseGameServices.instance.submitScore(
score: Score(
    androidLeaderboardID: 'android_leaderboard_id',
    iOSLeaderboardID: 'ios_leaderboard_id', 
    value: 5,
    )
);

Unlock achievement

To unlock an Achievement.
The Achievement takes three parameters:
-androidID the achievement id for android.
-iOSID the achievement id for iOS.
-percentComplete the completion percent of the achievement, this parameter is optional in case of iOS.
-steps the achievement steps for Android.

await FirebaseGameServices.instance.unlock(
achievement: Achievement(
    androidID: 'android_id', iOSID: 'ios_id',
    percentComplete: 100, steps: 2
    ),
);

Show achievements

await FirebaseGameServices.instance.showAchievements();

Player Name

To get the player name:

final playerName = await FirebaseGameServices.instance.getPlayerName();

Player Id

To get the player id:

final playerId = await FirebaseGameServices.instance.getPlayerId();

Platform specific #

Increment (Android Only)

To increment the steps for android achievement.

await FirebaseGameServices.instance.increment(achievement: Achievement(androidID: 'android_id', steps: 50));

Show AccessPoint (Apple Only)

await FirebaseGameServices.instance.showAccessPoint(AccessPointLocation.topLeading, showHighlights: true);

Show Dashboard (Apple Only)

await FirebaseGameServices.instance.showDashboard();

Show Player Profile (Apple Only)

await FirebaseGameServices.instance.showPlayerProfile();

Hide AccessPoint (Apple Only)

await FirebaseGameServices.instance.hideAccessPoint();

isUnderage (Apple Only)

Check if the player is underage.

await FirebaseGameServices.instance.isUnderage();

isMultiplayerGamingRestricted (Apple Only)

Check if the player can join multiplayer games.

await FirebaseGameServices.instance.isMultiplayerGamingRestricted();

isPersonalizedCommunicationRestricted (Apple Only)

Check if the player can use personalized communication.

await FirebaseGameServices.instance.isPersonalizedCommunicationRestricted();

Notice: This package was initally created to be used in-house, as such the development is first and foremost aligned with the internal requirements.

12
likes
140
pub points
61%
popularity

Publisher

unverified uploader

A Flutter package, linking Google's Play Games and Apple's Game Center with Firebase.

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

firebase_game_services_apple, firebase_game_services_google, firebase_game_services_platform_interface, flutter

More

Packages that depend on firebase_game_services