bloc
This commit is contained in:
24
lib/view_model/SendOtp/sendOtpObserver.dart
Normal file
24
lib/view_model/SendOtp/sendOtpObserver.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
// Define events
|
||||
abstract class SendOtpEvent {
|
||||
const SendOtpEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class SendOtp extends SendOtpEvent {
|
||||
final Map<String, String> loginData;
|
||||
SendOtp(this.loginData){
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object> get props => [loginData];
|
||||
|
||||
}
|
||||
|
||||
// Define states
|
||||
enum SendOtpState { initial, loading, success, failure }
|
||||
|
||||
33
lib/view_model/SendOtp/sendOtpbloc.dart
Normal file
33
lib/view_model/SendOtp/sendOtpbloc.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../Utils/base_manager.dart';
|
||||
import '../../resources/routes/route_name.dart';
|
||||
import '../Login/send_otp_api.dart';
|
||||
import 'sendOtpObserver.dart';
|
||||
|
||||
class SendOtpBloc extends Bloc<SendOtpEvent, SendOtpState> {
|
||||
SendOtpBloc() : super(SendOtpState.initial) {
|
||||
on<SendOtp>(mapEventToState);
|
||||
}
|
||||
Future<void> mapEventToState(
|
||||
SendOtp event, Emitter<SendOtpState> emit) async {
|
||||
if (event is SendOtp) {
|
||||
emit(SendOtpState.loading);
|
||||
try {
|
||||
final loginData = event.loginData;
|
||||
var resp = await SendOtpAPI(loginData).sendOtpApi();
|
||||
|
||||
if (resp.status == ResponseStatus.SUCCESS) {
|
||||
emit(SendOtpState.success);
|
||||
} else {
|
||||
emit(SendOtpState.failure);
|
||||
}
|
||||
} catch (e) {
|
||||
emit(SendOtpState.failure);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user