getCredential method

Future<Credential?> getCredential({
  1. String? accountType,
  2. String? serverClientId,
  3. String? idTokenNonce,
  4. bool? isIdTokenRequested,
  5. bool? isPasswordLoginSupported,
  6. bool showResolveDialog = false,
})

Tries to suggest a zero-click sign-in account. Only call this if your app does not currently know who is signed in. If zero-click suggestion fails app show dialog of credentials to choose from More about this https://developers.google.com/android/reference/com/google/android/gms/auth/api/credentials/CredentialsApi?hl=en#save(com.google.android.gms.common.api.GoogleApiClient,%20com.google.android.gms.auth.api.credentials.Credential)

Implementation

Future<Credential?> getCredential({
  // Identifier url, should be you App's website url
  String? accountType,
  String? serverClientId,
  String? idTokenNonce,
  bool? isIdTokenRequested,
  bool? isPasswordLoginSupported,
  // If we can't get credential without user interaction,
  // we can show dialog to prompt user to choose credential
  bool showResolveDialog = false,
}) async {
  if (_isAndroid(Methods.getCredential)) {
    try {
      final res = await _channel.invokeMethod(Methods.getCredential, {
        'accountType': accountType,
        'serverClientId': serverClientId,
        'idTokenNonce': idTokenNonce,
        'isIdTokenRequested': isIdTokenRequested,
        'isPasswordLoginSupported': isPasswordLoginSupported,
        'showResolveDialog': showResolveDialog,
      });

      if (res == null) return null;

      final Map<String, dynamic> map =
          jsonDecode(jsonEncode(res)) as Map<String, dynamic>;
      return Credential.fromJson(map);
    } catch (error) {
      debugPrint('Pinput/SmartAuth: getCredential failed: $error');
      return null;
    }
  }
  return null;
}