Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/presentation/auth/verification_cubit/verification_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<OTPVerificationState> {
AuthUseCase _authUseCase;
final AuthUseCase _authUseCase;

VerificationCubit(this._authUseCase) : super(InitialOTPState());

emitVerificationSentstate(String otp) {
void emitVerificationSentState(String otp) {
emit(OTPSentState(otp: otp));
}

_clear() async {
Future<void> _clearStoredOTPData() async {
await sp.deleteData('time');
await sp.deleteData('otp');
}

Future<void> sendEmailVerification() async {
emit(OTPSendingState());

final dataState = await _authUseCase.sendVerificationCode();

if (dataState is DataSuccess && dataState.data != null) {
if (dataState is DataSuccess<String> && 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());
}
Expand All @@ -36,10 +38,10 @@ class VerificationCubit extends Cubit<OTPVerificationState> {

final dataState = await _authUseCase.completeVerification();

if (dataState is DataSuccess && dataState.data != null) {
_clear();
if (dataState is DataSuccess<bool> && dataState.data == true) {
await _clearStoredOTPData();
appRouter.replaceNamed('/home');
} else if (dataState is DataFailed) {
} else {
emit(OTPFailureState());
}
}
Expand Down
12 changes: 6 additions & 6 deletions lib/presentation/auth/verification_cubit/verification_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.