rename method

Future<OtpAccount> rename(
  1. String accountId, {
  2. String? issuer,
  3. String? accountName,
})

Changes the displayed issuer and/or accountName of an account. null leaves a field unchanged.

Implementation

Future<OtpAccount> rename(
  String accountId, {
  String? issuer,
  String? accountName,
}) async {
  _checkOpen();
  if (accountName != null && accountName.trim().isEmpty) {
    throw const OtpConfigException(
      field: 'accountName',
      reason: 'must not be empty',
    );
  }
  final updated = await _repository.modify(
    accountId,
    (a) => a.copyWith(
      issuer: issuer == null
          ? null
          : () => issuer.trim().isEmpty ? null : issuer.trim(),
      accountName: accountName?.trim(),
    ),
  );
  await _notify();
  return updated;
}