-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
325 changed files
with
11,429 additions
and
5,299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule codelabs
updated
1613 files
5 changes: 5 additions & 0 deletions
5
examples/cookbook/games/achievements_leaderboards/analysis_options.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Take our settings from the example_utils analysis_options.yaml file. | ||
# If necessary for a particular example, this file can also include | ||
# overrides for individual lints. | ||
|
||
include: package:example_utils/analysis.yaml |
113 changes: 113 additions & 0 deletions
113
examples/cookbook/games/achievements_leaderboards/lib/games_services_controller.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:games_services/games_services.dart'; | ||
import 'package:logging/logging.dart'; | ||
|
||
/// Allows awarding achievements and leaderboard scores, | ||
/// and also showing the platforms' UI overlays for achievements | ||
/// and leaderboards. | ||
/// | ||
/// A facade of `package:games_services`. | ||
class GamesServicesController { | ||
static final Logger _log = Logger('GamesServicesController'); | ||
|
||
final Completer<bool> _signedInCompleter = Completer(); | ||
|
||
Future<bool> get signedIn => _signedInCompleter.future; | ||
|
||
/// Unlocks an achievement on Game Center / Play Games. | ||
/// | ||
/// You must provide the achievement ids via the [iOS] and [android] | ||
/// parameters. | ||
/// | ||
/// Does nothing when the game isn't signed into the underlying | ||
/// games service. | ||
Future<void> awardAchievement( | ||
{required String iOS, required String android}) async { | ||
if (!await signedIn) { | ||
_log.warning('Trying to award achievement when not logged in.'); | ||
return; | ||
} | ||
|
||
try { | ||
await GamesServices.unlock( | ||
achievement: Achievement( | ||
androidID: android, | ||
iOSID: iOS, | ||
), | ||
); | ||
} catch (e) { | ||
_log.severe('Cannot award achievement: $e'); | ||
} | ||
} | ||
|
||
/// Signs into the underlying games service. | ||
Future<void> initialize() async { | ||
try { | ||
await GamesServices.signIn(); | ||
// The API is unclear so we're checking to be sure. The above call | ||
// returns a String, not a boolean, and there's no documentation | ||
// as to whether every non-error result means we're safely signed in. | ||
final signedIn = await GamesServices.isSignedIn; | ||
_signedInCompleter.complete(signedIn); | ||
} catch (e) { | ||
_log.severe('Cannot log into GamesServices: $e'); | ||
_signedInCompleter.complete(false); | ||
} | ||
} | ||
|
||
/// Launches the platform's UI overlay with achievements. | ||
Future<void> showAchievements() async { | ||
if (!await signedIn) { | ||
_log.severe('Trying to show achievements when not logged in.'); | ||
return; | ||
} | ||
|
||
try { | ||
await GamesServices.showAchievements(); | ||
} catch (e) { | ||
_log.severe('Cannot show achievements: $e'); | ||
} | ||
} | ||
|
||
/// Launches the platform's UI overlay with leaderboard(s). | ||
Future<void> showLeaderboard() async { | ||
if (!await signedIn) { | ||
_log.severe('Trying to show leaderboard when not logged in.'); | ||
return; | ||
} | ||
|
||
try { | ||
await GamesServices.showLeaderboards( | ||
// TODO: When ready, change both these leaderboard IDs. | ||
iOSLeaderboardID: 'some_id_from_app_store', | ||
androidLeaderboardID: 'sOmE_iD_fRoM_gPlAy', | ||
); | ||
} catch (e) { | ||
_log.severe('Cannot show leaderboard: $e'); | ||
} | ||
} | ||
|
||
/// Submits [score] to the leaderboard. | ||
Future<void> submitLeaderboardScore(int score) async { | ||
if (!await signedIn) { | ||
_log.warning('Trying to submit leaderboard when not logged in.'); | ||
return; | ||
} | ||
|
||
_log.info('Submitting $score to leaderboard.'); | ||
|
||
try { | ||
await GamesServices.submitScore( | ||
score: Score( | ||
// TODO: When ready, change these leaderboard IDs. | ||
iOSLeaderboardID: 'some_id_from_app_store', | ||
androidLeaderboardID: 'sOmE_iD_fRoM_gPlAy', | ||
value: score, | ||
), | ||
); | ||
} catch (e) { | ||
_log.severe('Cannot submit leaderboard score: $e'); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
examples/cookbook/games/achievements_leaderboards/lib/various.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// ignore_for_file: unused_catch_clause | ||
|
||
import 'package:flutter/services.dart'; | ||
import 'package:games_services/games_services.dart'; | ||
|
||
void main() async { | ||
// #docregion signIn | ||
try { | ||
await GamesServices.signIn(); | ||
} on PlatformException catch (e) { | ||
// ... deal with failures ... | ||
} | ||
// #enddocregion signIn | ||
|
||
// #docregion unlock | ||
await GamesServices.unlock( | ||
achievement: Achievement( | ||
androidID: 'your android id', | ||
iOSID: 'your ios id', | ||
), | ||
); | ||
// #enddocregion unlock | ||
|
||
// #docregion showAchievements | ||
await GamesServices.showAchievements(); | ||
// #enddocregion showAchievements | ||
|
||
// #docregion submitScore | ||
await GamesServices.submitScore( | ||
score: Score( | ||
iOSLeaderboardID: 'some_id_from_app_store', | ||
androidLeaderboardID: 'sOmE_iD_fRoM_gPlAy', | ||
value: 100, | ||
), | ||
); | ||
// #enddocregion submitScore | ||
|
||
// #docregion showLeaderboards | ||
await GamesServices.showLeaderboards( | ||
iOSLeaderboardID: 'some_id_from_app_store', | ||
androidLeaderboardID: 'sOmE_iD_fRoM_gPlAy', | ||
); | ||
// #enddocregion showLeaderboards | ||
} |
19 changes: 19 additions & 0 deletions
19
examples/cookbook/games/achievements_leaderboards/pubspec.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: games_services_example | ||
description: Games services | ||
|
||
environment: | ||
sdk: ^3.2.0 | ||
|
||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
|
||
games_services: ^4.0.0 | ||
logging: ^1.2.0 | ||
|
||
dev_dependencies: | ||
example_utils: | ||
path: ../../../example_utils | ||
|
||
flutter: | ||
uses-material-design: true |
Oops, something went wrong.