diff --git a/lib/presentation/auth/verification_cubit/verification_cubit.dart b/lib/presentation/auth/verification_cubit/verification_cubit.dart index 08d1b97..bc55cef 100644 --- a/lib/presentation/auth/verification_cubit/verification_cubit.dart +++ b/lib/presentation/auth/verification_cubit/verification_cubit.dart @@ -5,27 +5,29 @@ import 'package:beacon/presentation/auth/verification_cubit/verification_state.d import 'package:flutter_bloc/flutter_bloc.dart'; class VerificationCubit extends Cubit { - AuthUseCase _authUseCase; + final AuthUseCase _authUseCase; + VerificationCubit(this._authUseCase) : super(InitialOTPState()); - emitVerificationSentstate(String otp) { + void emitVerificationSentState(String otp) { emit(OTPSentState(otp: otp)); } - _clear() async { + Future _clearStoredOTPData() async { await sp.deleteData('time'); await sp.deleteData('otp'); } Future sendEmailVerification() async { emit(OTPSendingState()); + final dataState = await _authUseCase.sendVerificationCode(); - if (dataState is DataSuccess && dataState.data != null) { + if (dataState is DataSuccess && dataState.data != null) { await sp.init(); await sp.saveData('time', DateTime.now().toIso8601String()); await sp.saveData('otp', dataState.data!); - emit(OTPSentState(otp: dataState.data)); + emit(OTPSentState(otp: dataState.data!)); } else { emit(OTPFailureState()); } @@ -36,10 +38,10 @@ class VerificationCubit extends Cubit { final dataState = await _authUseCase.completeVerification(); - if (dataState is DataSuccess && dataState.data != null) { - _clear(); + if (dataState is DataSuccess && dataState.data == true) { + await _clearStoredOTPData(); appRouter.replaceNamed('/home'); - } else if (dataState is DataFailed) { + } else { emit(OTPFailureState()); } } diff --git a/lib/presentation/auth/verification_cubit/verification_state.dart b/lib/presentation/auth/verification_cubit/verification_state.dart index 18c1ef9..f986b75 100644 --- a/lib/presentation/auth/verification_cubit/verification_state.dart +++ b/lib/presentation/auth/verification_cubit/verification_state.dart @@ -4,10 +4,10 @@ part 'verification_state.freezed.dart'; @freezed class OTPVerificationState with _$OTPVerificationState { - factory OTPVerificationState.initial() = InitialOTPState; - factory OTPVerificationState.otpSending() = OTPSendingState; - factory OTPVerificationState.otpSent({String? otp}) = OTPSentState; - factory OTPVerificationState.otpVerifying() = OTPVerifyingState; - factory OTPVerificationState.otpVerified() = OTPVerifiedState; - factory OTPVerificationState.failure() = OTPFailureState; + const factory OTPVerificationState.initial() = InitialOTPState; + const factory OTPVerificationState.otpSending() = OTPSendingState; + const factory OTPVerificationState.otpSent({String? otp}) = OTPSentState; + const factory OTPVerificationState.otpVerifying() = OTPVerifyingState; + const factory OTPVerificationState.otpVerified() = OTPVerifiedState; + const factory OTPVerificationState.failure({String? errorMessage}) = OTPFailureState; } diff --git a/lib/presentation/auth/verification_cubit/verification_state.freezed.dart b/lib/presentation/auth/verification_cubit/verification_state.freezed.dart index 688d823..1667fdb 100644 --- a/lib/presentation/auth/verification_cubit/verification_state.freezed.dart +++ b/lib/presentation/auth/verification_cubit/verification_state.freezed.dart @@ -96,21 +96,19 @@ class _$OTPVerificationStateCopyWithImpl<$Res, // ignore: unused_field final $Val _value; // ignore: unused_field - final $Res Function($Val) _then; -} - + final $Res Function(Val\) \_then; +\} /// @nodoc -abstract class _$$InitialOTPStateImplCopyWith<$Res> { - factory _$$InitialOTPStateImplCopyWith(_$InitialOTPStateImpl value, +abstract class \_$InitialOTPStateImplCopyWith<Res\> \{ +factory \_$InitialOTPStateImplCopyWith(_$InitialOTPStateImpl value, $Res Function(_$InitialOTPStateImpl) then) = - __$$InitialOTPStateImplCopyWithImpl<$Res>; -} - + __$$InitialOTPStateImplCopyWithImpl<Res\>; +\} /// @nodoc -class __$$InitialOTPStateImplCopyWithImpl<$Res> +class \_\_$InitialOTPStateImplCopyWithImpl<$Res> extends _$OTPVerificationStateCopyWithImpl<$Res, _$InitialOTPStateImpl> - implements _$$InitialOTPStateImplCopyWith<$Res> { - __$$InitialOTPStateImplCopyWithImpl( + implements _$$InitialOTPStateImplCopyWith<Res\> \{ +\_\_$InitialOTPStateImplCopyWithImpl( _$InitialOTPStateImpl _value, $Res Function(_$InitialOTPStateImpl) _then) : super(_value, _then); } @@ -118,7 +116,7 @@ class __$$InitialOTPStateImplCopyWithImpl<$Res> /// @nodoc class _$InitialOTPStateImpl implements InitialOTPState { - _$InitialOTPStateImpl(); + const _$InitialOTPStateImpl(); @override String toString() { @@ -222,21 +220,20 @@ class _$InitialOTPStateImpl implements InitialOTPState { } abstract class InitialOTPState implements OTPVerificationState { - factory InitialOTPState() = _$InitialOTPStateImpl; + const factory InitialOTPState() = _$InitialOTPStateImpl; } /// @nodoc -abstract class _$$OTPSendingStateImplCopyWith<$Res> { - factory _$$OTPSendingStateImplCopyWith(_$OTPSendingStateImpl value, +abstract class _$$OTPSendingStateImplCopyWith<Res\> \{ +factory \_$OTPSendingStateImplCopyWith(_$OTPSendingStateImpl value, $Res Function(_$OTPSendingStateImpl) then) = - __$$OTPSendingStateImplCopyWithImpl<$Res>; -} - + __$$OTPSendingStateImplCopyWithImpl<Res\>; +\} /// @nodoc -class __$$OTPSendingStateImplCopyWithImpl<$Res> +class \_\_$OTPSendingStateImplCopyWithImpl<$Res> extends _$OTPVerificationStateCopyWithImpl<$Res, _$OTPSendingStateImpl> - implements _$$OTPSendingStateImplCopyWith<$Res> { - __$$OTPSendingStateImplCopyWithImpl( + implements _$$OTPSendingStateImplCopyWith<Res\> \{ +\_\_$OTPSendingStateImplCopyWithImpl( _$OTPSendingStateImpl _value, $Res Function(_$OTPSendingStateImpl) _then) : super(_value, _then); } @@ -244,7 +241,7 @@ class __$$OTPSendingStateImplCopyWithImpl<$Res> /// @nodoc class _$OTPSendingStateImpl implements OTPSendingState { - _$OTPSendingStateImpl(); + const _$OTPSendingStateImpl(); @override String toString() { @@ -348,23 +345,22 @@ class _$OTPSendingStateImpl implements OTPSendingState { } abstract class OTPSendingState implements OTPVerificationState { - factory OTPSendingState() = _$OTPSendingStateImpl; + const factory OTPSendingState() = _$OTPSendingStateImpl; } /// @nodoc -abstract class _$$OTPSentStateImplCopyWith<$Res> { - factory _$$OTPSentStateImplCopyWith( +abstract class _$$OTPSentStateImplCopyWith<Res\> \{ +factory \_$OTPSentStateImplCopyWith( _$OTPSentStateImpl value, $Res Function(_$OTPSentStateImpl) then) = __$$OTPSentStateImplCopyWithImpl<$Res>; @useResult - $Res call({String? otp}); -} - + Res call\(\{String? otp\}\); +\} /// @nodoc -class __$$OTPSentStateImplCopyWithImpl<$Res> +class \_\_$OTPSentStateImplCopyWithImpl<$Res> extends _$OTPVerificationStateCopyWithImpl<$Res, _$OTPSentStateImpl> - implements _$$OTPSentStateImplCopyWith<$Res> { - __$$OTPSentStateImplCopyWithImpl( + implements _$$OTPSentStateImplCopyWith<Res\> \{ +\_\_$OTPSentStateImplCopyWithImpl( _$OTPSentStateImpl _value, $Res Function(_$OTPSentStateImpl) _then) : super(_value, _then); @@ -385,7 +381,7 @@ class __$$OTPSentStateImplCopyWithImpl<$Res> /// @nodoc class _$OTPSentStateImpl implements OTPSentState { - _$OTPSentStateImpl({this.otp}); + const _$OTPSentStateImpl({this.otp}); @override final String? otp; @@ -500,7 +496,7 @@ class _$OTPSentStateImpl implements OTPSentState { } abstract class OTPSentState implements OTPVerificationState { - factory OTPSentState({final String? otp}) = _$OTPSentStateImpl; + const factory OTPSentState({final String? otp}) = _$OTPSentStateImpl; String? get otp; @JsonKey(ignore: true) @@ -509,17 +505,16 @@ abstract class OTPSentState implements OTPVerificationState { } /// @nodoc -abstract class _$$OTPVerifyingStateImplCopyWith<$Res> { - factory _$$OTPVerifyingStateImplCopyWith(_$OTPVerifyingStateImpl value, +abstract class _$$OTPVerifyingStateImplCopyWith<Res\> \{ +factory \_$OTPVerifyingStateImplCopyWith(_$OTPVerifyingStateImpl value, $Res Function(_$OTPVerifyingStateImpl) then) = - __$$OTPVerifyingStateImplCopyWithImpl<$Res>; -} - + __$$OTPVerifyingStateImplCopyWithImpl<Res\>; +\} /// @nodoc -class __$$OTPVerifyingStateImplCopyWithImpl<$Res> +class \_\_$OTPVerifyingStateImplCopyWithImpl<$Res> extends _$OTPVerificationStateCopyWithImpl<$Res, _$OTPVerifyingStateImpl> - implements _$$OTPVerifyingStateImplCopyWith<$Res> { - __$$OTPVerifyingStateImplCopyWithImpl(_$OTPVerifyingStateImpl _value, + implements _$$OTPVerifyingStateImplCopyWith<Res\> \{ +\_\_$OTPVerifyingStateImplCopyWithImpl(_$OTPVerifyingStateImpl _value, $Res Function(_$OTPVerifyingStateImpl) _then) : super(_value, _then); } @@ -527,7 +522,7 @@ class __$$OTPVerifyingStateImplCopyWithImpl<$Res> /// @nodoc class _$OTPVerifyingStateImpl implements OTPVerifyingState { - _$OTPVerifyingStateImpl(); + const _$OTPVerifyingStateImpl(); @override String toString() { @@ -631,21 +626,20 @@ class _$OTPVerifyingStateImpl implements OTPVerifyingState { } abstract class OTPVerifyingState implements OTPVerificationState { - factory OTPVerifyingState() = _$OTPVerifyingStateImpl; + const factory OTPVerifyingState() = _$OTPVerifyingStateImpl; } /// @nodoc -abstract class _$$OTPVerifiedStateImplCopyWith<$Res> { - factory _$$OTPVerifiedStateImplCopyWith(_$OTPVerifiedStateImpl value, +abstract class _$$OTPVerifiedStateImplCopyWith<Res\> \{ +factory \_$OTPVerifiedStateImplCopyWith(_$OTPVerifiedStateImpl value, $Res Function(_$OTPVerifiedStateImpl) then) = - __$$OTPVerifiedStateImplCopyWithImpl<$Res>; -} - + __$$OTPVerifiedStateImplCopyWithImpl<Res\>; +\} /// @nodoc -class __$$OTPVerifiedStateImplCopyWithImpl<$Res> +class \_\_$OTPVerifiedStateImplCopyWithImpl<$Res> extends _$OTPVerificationStateCopyWithImpl<$Res, _$OTPVerifiedStateImpl> - implements _$$OTPVerifiedStateImplCopyWith<$Res> { - __$$OTPVerifiedStateImplCopyWithImpl(_$OTPVerifiedStateImpl _value, + implements _$$OTPVerifiedStateImplCopyWith<Res\> \{ +\_\_$OTPVerifiedStateImplCopyWithImpl(_$OTPVerifiedStateImpl _value, $Res Function(_$OTPVerifiedStateImpl) _then) : super(_value, _then); } @@ -653,7 +647,7 @@ class __$$OTPVerifiedStateImplCopyWithImpl<$Res> /// @nodoc class _$OTPVerifiedStateImpl implements OTPVerifiedState { - _$OTPVerifiedStateImpl(); + const _$OTPVerifiedStateImpl(); @override String toString() { @@ -757,7 +751,7 @@ class _$OTPVerifiedStateImpl implements OTPVerifiedState { } abstract class OTPVerifiedState implements OTPVerificationState { - factory OTPVerifiedState() = _$OTPVerifiedStateImpl; + const factory OTPVerifiedState() = _$OTPVerifiedStateImpl; } /// @nodoc @@ -771,15 +765,15 @@ abstract class _$$OTPFailureStateImplCopyWith<$Res> { class __$$OTPFailureStateImplCopyWithImpl<$Res> extends _$OTPVerificationStateCopyWithImpl<$Res, _$OTPFailureStateImpl> implements _$$OTPFailureStateImplCopyWith<$Res> { - __$$OTPFailureStateImplCopyWithImpl( - _$OTPFailureStateImpl _value, $Res Function(_$OTPFailureStateImpl) _then) + __$$OTPFailureStateImplCopyWithImpl(_$OTPFailureStateImpl _value, + $Res Function(_$OTPFailureStateImpl) _then) : super(_value, _then); } /// @nodoc class _$OTPFailureStateImpl implements OTPFailureState { - _$OTPFailureStateImpl(); + const _$OTPFailureStateImpl(); @override String toString() { @@ -883,5 +877,5 @@ class _$OTPFailureStateImpl implements OTPFailureState { } abstract class OTPFailureState implements OTPVerificationState { - factory OTPFailureState() = _$OTPFailureStateImpl; -} + const factory OTPFailureState() = _$OTPFailureStateImpl; +} \ No newline at end of file