firebase_game_services 2.0.0 copy "firebase_game_services: ^2.0.0" to clipboard
firebase_game_services: ^2.0.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.

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();

Sign in linked user

Signs in the currently linked user with native Game Service (Play Games on Android and GameCenter on iOS) to Firebase.

await FirebaseGameServices.instance.signInLinkedUser();

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 auth = FirebaseAuth.instance;

    try {
        if (auth.currentUser != null) {
        if (myValue == null || myValue.isEmpty) {
            throw Exception('myValue cannot be null or empty');
        }
        
        await firestore.collection("my-collection").doc(auth.currentUser!.uid).set(
            {
            "my-field": myValue,
            },
            SetOptions(merge: true),
        );
        } 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 leaderboards

To show the leaderboards screen. It takes the leaderbord id for android and iOS.

await FirebaseGameServices.instance.showLeaderboards(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();

Sign out

Signs the user out (not recommended):

await FirebaseAuth.instance.signOut();

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 (iOS Only)

To show the access point you can call the following function:

await FirebaseGameServices.instance.showAccessPoint(AccessPointLocation.topLeading);

isUnderage (iOS Only)

Check if the player is underage.

await FirebaseGameServices.instance.isUnderage();

isMultiplayerGamingRestricted (iOS Only)

Check if the player can join multiplayer games.

await FirebaseGameServices.instance.isMultiplayerGamingRestricted();

isPersonalizedCommunicationRestricted (iOS 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
0
pub points
57%
popularity

Publisher

unverified uploader

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

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

firebase_game_services_apple, firebase_game_services_google, firebase_game_services_platform_interface, flutter

More

Packages that depend on firebase_game_services