saveCredential method

Future<bool> saveCredential({
  1. required String id,
  2. String? accountType,
  3. String? name,
  4. String? password,
  5. String? profilePictureUri,
})

Saves a credential that was used to sign in to the app. If disableAutoSignIn was previously called and the save operation succeeds, auto sign-in will be re-enabled if the user's settings permit this.

Note: On Android O and above devices save requests that require showing a save confirmation may be cancelled in favor of the active Autofill service's save dialog. This behavior may be overridden by using Auth.AuthCredentialsOptions.Builder.forceEnableSaveDialog(). Please see the overview documentation for more details on providing the best user experience when targeting Android O and above. 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<bool> saveCredential({
  // Value you want to save
  required String id,
  // Identifier url, should be you App's website url
  String? accountType,
  String? name,
  String? password,
  String? profilePictureUri,
}) async {
  if (_isAndroid(Methods.saveCredential)) {
    try {
      final res = await _channel.invokeMethod(Methods.saveCredential, {
        'id': id,
        'accountType': accountType,
        'name': name,
        'password': password,
        'profilePictureUri': profilePictureUri,
      });
      return res == true;
    } catch (error) {
      debugPrint('Pinput/SmartAuth: saveCredential failed: $error');
      return false;
    }
  }
  return false;
}