selfprivacy.org.app/lib/logic/cubit/recovery_key/recovery_key_state.dart

40 lines
1.1 KiB
Dart
Raw Normal View History

2022-05-24 16:09:47 +00:00
part of 'recovery_key_cubit.dart';
class RecoveryKeyState extends ServerInstallationDependendState {
const RecoveryKeyState(this._status, this.loadingStatus);
2022-05-24 18:55:39 +00:00
const RecoveryKeyState.initial()
: this(
const RecoveryKeyStatus(exists: false, valid: false),
LoadingStatus.refreshing,
);
2022-05-24 16:09:47 +00:00
final RecoveryKeyStatus _status;
final LoadingStatus loadingStatus;
bool get exists => _status.exists;
bool get isValid => _status.valid;
DateTime? get generatedAt => _status.date;
DateTime? get expiresAt => _status.expiration;
2022-05-24 16:09:47 +00:00
int? get usesLeft => _status.usesLeft;
bool get isInvalidBecauseExpired =>
_status.expiration != null &&
_status.expiration!.isBefore(DateTime.now());
bool get isInvalidBecauseUsed =>
_status.usesLeft != null && _status.usesLeft == 0;
2022-05-24 16:09:47 +00:00
@override
List<Object> get props => [_status, loadingStatus];
RecoveryKeyState copyWith({
2022-06-05 19:36:32 +00:00
final RecoveryKeyStatus? status,
final LoadingStatus? loadingStatus,
}) =>
RecoveryKeyState(
status ?? _status,
loadingStatus ?? this.loadingStatus,
);
2022-05-24 16:09:47 +00:00
}