40 lines
1.4 KiB
Dart
40 lines
1.4 KiB
Dart
// lib/presentation/bloc/auth/auth_bloc.dart
|
|
import 'package:equatable/equatable.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
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: 2));
|
|
if (event.phoneNumber.endsWith('0000')) {
|
|
emit(const AuthFailure('شماره وارد شده نامعتبر است.'));
|
|
} else {
|
|
emit(AuthCodeSentSuccess());
|
|
}
|
|
});
|
|
|
|
// مدیریت رویداد تایید کد
|
|
on<VerifyOtpEvent>((event, emit) async {
|
|
emit(AuthLoading());
|
|
await Future.delayed(const Duration(seconds: 2));
|
|
if (event.otpCode == '12345') { // یک کد جادویی برای تست
|
|
emit(AuthVerified());
|
|
} else {
|
|
emit(const AuthFailure('کد وارد شده صحیح نمیباشد.'));
|
|
}
|
|
});
|
|
on<UpdateUserInfoEvent>((event, emit) async {
|
|
emit(AuthLoading());
|
|
await Future.delayed(const Duration(seconds: 2));
|
|
// در اینجا منطق واقعی ذخیره در سرور یا دیتابیس قرار میگیرد
|
|
print('User Info Saved: Name=${event.name}, Gender=${event.gender}');
|
|
emit(UserInfoUpdateSuccess());
|
|
});
|
|
}
|
|
} |