unified_game_services_playfab 0.1.0 copy "unified_game_services_playfab: ^0.1.0" to clipboard
unified_game_services_playfab: ^0.1.0 copied to clipboard

PlayFab provider for unified_game_services, using the PlayFab Client API over REST (pure Dart).

example/unified_game_services_playfab_example.dart

// Minimal PlayFab provider walkthrough.
//
// Run against a real title with:
//   dart run example/unified_game_services_playfab_example.dart
// after setting PLAYFAB_TITLE_ID and PLAYFAB_CUSTOM_ID in the environment.
import 'dart:io';
import 'dart:typed_data';

import 'package:unified_game_services_playfab/unified_game_services_playfab.dart';

Future<void> main() async {
  final titleId = Platform.environment['PLAYFAB_TITLE_ID'];
  final customId =
      Platform.environment['PLAYFAB_CUSTOM_ID'] ?? 'example-player';
  if (titleId == null) {
    stderr.writeln('Set PLAYFAB_TITLE_ID to run this example.');
    exit(64);
  }

  final provider = PlayFabProvider(
    titleId: titleId,
    customId: customId,
    displayName: 'Example Player',
    // Map a unified leaderboard key to a PlayFab statistic name.
    leaderboardIds: const {'high': 'HighScore'},
  );

  final player = await provider.signIn();
  print('Signed in as ${player?.displayName} (${player?.id})');

  await provider.submitScore(leaderboardId: 'high', score: 4200);
  final board = await provider.getLeaderboard('high');
  for (final e in board.entries) {
    print('#${e.rank} ${e.player.displayName} — ${e.displayScore}');
  }

  await provider.setStat('kills', 10);
  await provider.incrementStat('kills', by: 5);
  print('kills = ${(await provider.getStat('kills'))?.value}');

  await provider.saveData('slot0', Uint8List.fromList([1, 2, 3, 4]));
  final save = await provider.loadData('slot0');
  print('loaded ${save?.metadata.sizeBytes} bytes');

  await provider.dispose();
}
0
likes
160
points
8
downloads

Documentation

API reference

Publisher

verified publisheraprimo.dev

Weekly Downloads

PlayFab provider for unified_game_services, using the PlayFab Client API over REST (pure Dart).

Repository (GitHub)
View/report issues

Topics

#game-services #achievements #leaderboards #playfab #gamedev

License

MIT (license)

Dependencies

http, unified_game_services_platform_interface

More

Packages that depend on unified_game_services_playfab