Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Add ability to create games sign in #511

Merged

Conversation

ihildebrandt
Copy link
Contributor

This introduces an additional init argument so that a games sign in experience can be created in Android. The native iOS code will return an error if attempting to create a games sign in.

Additionally, the Android plugin publishes the GoogleSignInAccount so that it can be accessed by other native code.

@ihildebrandt ihildebrandt force-pushed the ihildebrandt/games_sign_in branch 2 times, most recently from b0a7574 to b318fc8 Compare April 30, 2018 02:55
Copy link
Contributor

@mravn-google mravn-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

/// Equivalent to GoogleSignInOptions.DEFAULT_SIGN_IN
static const String defaultSignInOptions = "defaultSignIn";

/// Equivalent to GoogleSignInOptions.DEFAULT_GAMES_Sign_In
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be DEFAULT_GAMES_SIGN_IN

static const String defaultGamesSignInOptions = "defaultGamesSignIn";

/// The options to pass to GoogleSignInOptions.Builder()
final String builderOptions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This property is named after an implementation detail on the Android side (the builder). Maybe rename to defaultConfiguration, signInOptions or similar? Renaming should be done also for the MethodChannel argument name.

The String type may be too wide. Perhaps use an enum instead?

@@ -142,7 +151,21 @@ class GoogleSignIn {
/// The [hostedDomain] argument specifies a hosted domain restriction. By
/// setting this, sign in will be restricted to accounts of the user in the
/// specified domain. By default, the list of accounts will not be restricted.
GoogleSignIn({this.scopes, this.hostedDomain});
GoogleSignIn({this.builderOptions, this.scopes, this.hostedDomain});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to assert that the builderOptions has a valid value. (With an enum rather than a String we don't need that.)

@@ -380,6 +403,7 @@ private void onSignInResult(GoogleSignInResult result) {
if (result.isSuccess()) {
GoogleSignInAccount account = result.getSignInAccount();
currentAccount = account;
registrar.publish(account);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were planning to deprecate the value publishing API. Can't potential clients use the GoogleSignIn API directly to get the account?

new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail();
GoogleSignInOptions.Builder optionsBuilder;

if (builderOptions == null) builderOptions = DEFAULT_SIGN_IN;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be necessary, as we ensure the parameter has a non-null value on the Dart side.

@mravn-google mravn-google self-assigned this Apr 30, 2018
@ihildebrandt
Copy link
Contributor Author

@mravn-google Thanks for the review. I believe I addressed all of your notes. Swapping to a direct API call in my downstream plugin worked.

Let me know if there's anything else I can clean up.

@ihildebrandt ihildebrandt force-pushed the ihildebrandt/games_sign_in branch 2 times, most recently from 4bd76da to f66a147 Compare April 30, 2018 19:17
result([FlutterError errorWithCode:@"missing-config"
message:@"GoogleService-Info.plist file not found"
if ([((NSNumber *)call.arguments[@"signInOption"]) isEqualToNumber:[NSNumber
numberWithInt:1]]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe simpler with

NSNumber* signInOption = call.arguments[@"signInOption"];
if ([signInOption intValue] == 1) {
  ...
}

Copy link
Contributor

@mravn-google mravn-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Added some additional comments.

@@ -127,6 +129,9 @@ class GoogleSignIn {
static const MethodChannel channel =
const MethodChannel('plugins.flutter.io/google_sign_in');

/// The options to pass to GoogleSignInOptions.Builder()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not mention the Android API's builder here, but instead document what SignInOption is, in its own right. And we should document that gamesSignIn isn't supported on iOS.

GoogleSignIn({this.scopes, this.hostedDomain});
GoogleSignIn({this.signInOption, this.scopes, this.hostedDomain});

/// Factory for creating default sign in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Dartdoc opening paragraph should end in a .

Same for GoogleSignIn.gamesSignIn below.

hostedDomain: hostedDomain);
}

/// Factory for creating sign in suitable for games
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document that this does not work on iOS.

@@ -13,6 +13,8 @@ import 'src/common.dart';
export 'src/common.dart';
export 'widgets.dart';

enum SignInOption { defaultSignIn, gamesSignIn }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call these standard and games. The SignIn part is already given by the enum type name.

GoogleSignIn({this.signInOption, this.scopes, this.hostedDomain});

/// Factory for creating default sign in
factory GoogleSignIn.defaultSignIn(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename the factory constructors GoogleSignIn.standard and GoogleSignIn.games, again to avoid repeating the SignIn part in client code.

@@ -173,7 +192,8 @@ class GoogleSignIn {

Future<void> _ensureInitialized() {
if (_initialization == null) {
_initialization = channel.invokeMethod("init", <String, dynamic>{
_initialization = channel.invokeMethod('init', <String, dynamic>{
'signInOption': (signInOption ?? SignInOption.defaultSignIn).index,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe keep this as a String in the channel communication and on the platform side. 0 and 1 are just magic constants otherwise, with non-obvious relationship to the Dart enum.

Copy link
Contributor

@mravn-google mravn-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mravn-google
Copy link
Contributor

mravn-google commented May 1, 2018

Thanks a lot! Can I ask you to address the compile error and formatting discrepancies reported by Travis?

message:@"Games sign in is not supported on iOS"
details:nil]);
NSString *signInOption = call.arguments[@"signInOption"];
if ([signInOption isEqualToString] == @"SignInOption.games") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. You meant [sigInOption isEqualtoString:@"SignInOption.games"] :-)

@mravn-google mravn-google merged commit 31e298a into flutter:master May 1, 2018
@mravn-google
Copy link
Contributor

Published after #519

@ihildebrandt ihildebrandt deleted the ihildebrandt/games_sign_in branch May 1, 2018 15:03
haydenflinner pushed a commit to haydenflinner/plugins that referenced this pull request May 4, 2018
slightfoot pushed a commit to slightfoot/plugins that referenced this pull request Jun 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
3 participants