Skip to content
This repository has been archived by the owner on Mar 27, 2022. It is now read-only.

Null safety #24

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"play_games","path":"D:\\\\My Workspace\\\\My Work\\\\GitHub Repos\\\\play_games\\\\","dependencies":[]}],"android":[{"name":"play_games","path":"D:\\\\My Workspace\\\\My Work\\\\GitHub Repos\\\\play_games\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"play_games","dependencies":[]}],"date_created":"2021-04-28 03:19:39.941477","version":"2.0.5"}
13 changes: 13 additions & 0 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=C:\flutter"
export "FLUTTER_APPLICATION_PATH=D:\My Workspace\My Work\GitHub Repos\play_games\example"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build\ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=false"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.packages"
116 changes: 56 additions & 60 deletions lib/play_games.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,55 +40,55 @@ enum TimeSpan { TIME_SPAN_DAILY, TIME_SPAN_WEEKLY, TIME_SPAN_ALL_TIME }
enum CollectionType { COLLECTION_PUBLIC }

class SubmitScoreSingleResult {
int rawScore;
String formattedScore;
bool newBest;
String scoreTag;
int? rawScore;
String? formattedScore;
bool? newBest;
String? scoreTag;
}

class SubmitScoreResults {
String type;
String leaderboardId;
String playerId;
SubmitScoreSingleResult scoreResultDaily;
SubmitScoreSingleResult scoreResultWeekly;
SubmitScoreSingleResult scoreResultAllTime;
String? type;
String? leaderboardId;
String? playerId;
SubmitScoreSingleResult? scoreResultDaily;
SubmitScoreSingleResult? scoreResultWeekly;
SubmitScoreSingleResult? scoreResultAllTime;
}

class ScoreResult {
String displayRank;
String displayScore;
int rank;
int rawScore;
String scoreTag;
int timestampMillis;
String scoreHolderDisplayName;
String? displayRank;
String? displayScore;
int? rank;
int? rawScore;
String? scoreTag;
int? timestampMillis;
String? scoreHolderDisplayName;
}

class ScoreResults {
String leaderboardDisplayName;
List<ScoreResult> scores;
String? leaderboardDisplayName;
List<ScoreResult>? scores;
}

SigninResultType _typeFromStr(String value) {
SigninResultType _typeFromStr(String? value) {
return SigninResultType.values
.firstWhere((e) => e.toString().split('.')[1] == value);
}

class SigninResult {
SigninResultType type;
Account account;
String message;
SigninResultType? type;
Account? account;
String? message;

bool get success => type == SigninResultType.SUCCESS;
}

class Account {
String id;
String displayName;
String email;
String hiResImageUri;
String iconImageUri;
String? id;
String? displayName;
String? email;
String? hiResImageUri;
String? iconImageUri;

Future<Image> get hiResImage async =>
await _fetchToMemory(await _channel.invokeMethod('getHiResImage'));
Expand All @@ -98,18 +98,17 @@ class Account {
}

class Snapshot {
String content;
Map<String, String> metadata;
String? content;
Map<String, String>? metadata;

Snapshot.fromMap(Map data) {
this.content = data['content'];
this.metadata = (data['metadata'] as Map<dynamic, dynamic> ?? {})
.cast<String, String>();
this.metadata = (data['metadata'] ?? {}).cast<String, String>();
}
}

Future<Image> _fetchToMemory(Map<dynamic, dynamic> result) {
Uint8List bytes = result['bytes'];
Uint8List? bytes = result['bytes'];
if (bytes == null) {
print('was null, mate');
return Future.value(null);
Expand All @@ -120,47 +119,46 @@ Future<Image> _fetchToMemory(Map<dynamic, dynamic> result) {
}

class PlayGames {
static Future<bool> unlockAchievementById(String id) async {
static Future<bool?> unlockAchievementById(String id) async {
return await _channel.invokeMethod('unlockAchievementById', {'id': id});
}

static Future<bool> unlockAchievementByName(String name) async {
static Future<bool?> unlockAchievementByName(String name) async {
return await _channel
.invokeMethod('unlockAchievementByName', {'name': name});
}

static Future<bool> incrementAchievementById(String id,
static Future<bool?> incrementAchievementById(String id,
[int amount = 1]) async {
return await _channel
.invokeMethod('incrementAchievementById', {'id': id, 'amount': amount});
}

static Future<bool> incrementAchievementByName(String name,
static Future<bool?> incrementAchievementByName(String name,
[int amount = 1]) async {
return await _channel.invokeMethod(
'incrementAchievementByName', {'name': name, 'amount': amount});
}

// TODO better way to set gravity
static Future<bool> setPopupOptions(
static Future<bool?> setPopupOptions(
{bool show = true, int gravity = 49}) async {
return await _channel
.invokeMethod('setPopupOptions', {'show': show, 'gravity': gravity});
}

static Future<bool> showAchievements() async {
static Future<bool?> showAchievements() async {
final Map<dynamic, dynamic> map =
await _channel.invokeMethod('showAchievements');
return map['closed'];
}

static Future<bool> showLeaderboard(String leaderboardId) async {
static Future<bool?> showLeaderboard(String leaderboardId) async {
final Map<dynamic, dynamic> map = await _channel
.invokeMethod('showLeaderboard', {'leaderboardId': leaderboardId});
return map['closed'];
}

static Future<bool> showAllLeaderboards() async {
static Future<bool?> showAllLeaderboards() async {
final Map<dynamic, dynamic> map =
await _channel.invokeMethod('showAllLeaderboards');
return map['closed'];
Expand All @@ -183,15 +181,14 @@ class PlayGames {
return Snapshot.fromMap(map);
}

static Future<bool> saveSnapshot(String name, String content,
static Future<bool?> saveSnapshot(String name, String content,
{Map<String, String> metadata = const {}}) async {
final Map<dynamic, dynamic> result = await _channel.invokeMethod(
'saveSnapshot',
{'snapshotName': name, 'content': content, 'metadata': metadata});
if (result['type'] != null && !result['type'].isEmpty) {
if (result['type'] != null && !result['type'].isEmpty)
throw new CloudSaveError(result['type'], result['message']);
}
return result['status'] as bool;
return result['status'];
}

static Future<Snapshot> resolveSnapshotConflict(
Expand Down Expand Up @@ -243,11 +240,8 @@ class PlayGames {
..scoreResultAllTime = _parseSubmitSingleScore(map['scoreResultAllTime']);
}

static SubmitScoreSingleResult _parseSubmitSingleScore(
static SubmitScoreSingleResult? _parseSubmitSingleScore(
Map<dynamic, dynamic> map) {
if (map == null) {
return null;
}
return SubmitScoreSingleResult()
..rawScore = map['rawScore']
..formattedScore = map['formattedScore']
Expand Down Expand Up @@ -318,9 +312,8 @@ class PlayGames {
static ScoreResults _parseScoreResults(Map<dynamic, dynamic> map) {
return ScoreResults()
..leaderboardDisplayName = map['leaderboardDisplayName']
..scores = (map['scores'] as List)
.map((el) => _parseScoreResult(el as Map<dynamic, dynamic>))
.toList();
..scores =
(map['scores'] as List).map((el) => _parseScoreResult(el)).toList();
}

static ScoreResult _parseScoreResult(Map<dynamic, dynamic> map) {
Expand All @@ -334,9 +327,14 @@ class PlayGames {
}

static Future<SigninResult> signIn(
{bool requestEmail = true, bool scopeSnapshot = false, bool silentSignInOnly = false}) async {
final Map<dynamic, dynamic> map = await _channel.invokeMethod('signIn',
{'requestEmail': requestEmail, 'scopeSnapshot': scopeSnapshot, 'silentSignInOnly': silentSignInOnly});
{bool requestEmail = true,
bool scopeSnapshot = false,
bool silentSignInOnly = false}) async {
final Map<dynamic, dynamic> map = await _channel.invokeMethod('signIn', {
'requestEmail': requestEmail,
'scopeSnapshot': scopeSnapshot,
'silentSignInOnly': silentSignInOnly
});
SigninResultType type = _typeFromStr(map['type']);
SigninResult result = new SigninResult()..type = type;
if (type == SigninResultType.SUCCESS) {
Expand All @@ -346,9 +344,8 @@ class PlayGames {
..email = map['email']
..hiResImageUri = map['hiResImageUri']
..iconImageUri = map['iconImageUri'];
} else {
} else
result.message = map['message'];
}
return result;
}

Expand All @@ -365,9 +362,8 @@ class PlayGames {
..email = map['email']
..hiResImageUri = map['hiResImageUri']
..iconImageUri = map['iconImageUri'];
} else {
} else
result.message = map['message'];
}
}
return result;
}
Expand Down
5 changes: 2 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
name: play_games
description: A simple wrapper on top of Google Play Games Services (GPGS), including auth, achievement, and more.
version: 0.5.5
version: 1.0.0
homepage: https://github.com/luanpotter/play_games

environment:
sdk: ">=2.6.0 <3.0.0"
flutter: ">=1.10.0 <2.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
Expand Down