44 lines
1.2 KiB
Dart
44 lines
1.2 KiB
Dart
import 'package:bloc/bloc.dart';
|
|
import 'package:meta/meta.dart';
|
|
import 'dart:async';
|
|
|
|
part 'auth_event.dart';
|
|
part 'auth_state.dart';
|
|
|
|
class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|
AuthBloc() : super(AuthInitial()) {
|
|
on<SendOTPEvent>((event, emit) async {
|
|
emit(AuthLoading());
|
|
await Future.delayed(const Duration(seconds: 1));
|
|
if (event.phoneNumber.isNotEmpty) {
|
|
emit(AuthCodeSentSuccess());
|
|
} else {
|
|
emit(AuthFailure('شماره موبایل معتبر نیست.'));
|
|
}
|
|
});
|
|
|
|
on<VerifyOTPEvent>((event, emit) async {
|
|
emit(AuthLoading());
|
|
await Future.delayed(const Duration(seconds: 1));
|
|
if (event.otp == '12345') {
|
|
emit(AuthVerified());
|
|
} else {
|
|
emit(AuthFailure('کد تایید صحیح نمیباشد.'));
|
|
}
|
|
});
|
|
|
|
on<SaveUserInfoEvent>((event, emit) async {
|
|
emit(AuthLoading());
|
|
await Future.delayed(const Duration(milliseconds: 500));
|
|
|
|
print('User info to save: Name: ${event.name}, Gender: ${event.gender}');
|
|
|
|
if (event.name.trim().isEmpty) {
|
|
emit(AuthFailure('لطفاً نام خود را وارد کنید.'));
|
|
} else {
|
|
emit(UserInfoSaved());
|
|
}
|
|
});
|
|
}
|
|
}
|