Dart package linking Google's Play Games and Apple's Game Center with Firebase.
If you continue to encounter difficulties, kindly refer to the following discussion for further assistance: Troubleshooting Guide.
Android minSdkVersion >=19
iOS >=12.0
macOS >=12.0
Call this before making any other action.
await FirebaseGameServices.instance.signIn();
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.
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.
Shows all leaderboards.
await FirebaseGameServices.instance.showAllLeaderboards();
Shows a single leaderboard.
await FirebaseGameServices.instance.showSingleLeaderboard(iOSLeaderboardID: 'ios_leaderboard_id', androidLeaderboardID: 'android_leaderboard_id');
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,
)
);
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
),
);
await FirebaseGameServices.instance.showAchievements();
To get the player name:
final playerName = await FirebaseGameServices.instance.getPlayerName();
To get the player id:
final playerId = await FirebaseGameServices.instance.getPlayerId();
To increment the steps for android achievement.
await FirebaseGameServices.instance.increment(achievement: Achievement(androidID: 'android_id', steps: 50));
await FirebaseGameServices.instance.showAccessPoint(AccessPointLocation.topLeading, showHighlights: true);
await FirebaseGameServices.instance.showDashboard();
await FirebaseGameServices.instance.showPlayerProfile();
await FirebaseGameServices.instance.hideAccessPoint();
Check if the player is underage.
await FirebaseGameServices.instance.isUnderage();
Check if the player can join multiplayer games.
await FirebaseGameServices.instance.isMultiplayerGamingRestricted();
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.