This commit is contained in:
rajshinde046
2024-05-02 16:56:33 +05:30
parent 6806a3a09d
commit c0ad2d6b91
12 changed files with 513 additions and 327 deletions

View File

@@ -0,0 +1,24 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'Loginobserver.dart';
class CounterBloc extends Bloc<CounterEvents, CounterStates> {
int counter = 0;
CounterBloc() : super(UpdateState(0)) {
on<NumberIncreaseEvent>(onNumberIncrease);
on<NumberDecreaseEvent>(onNumberDecrease);
}
void onNumberIncrease(
NumberIncreaseEvent event, Emitter<CounterStates> emit) async {
counter = counter + 1;
emit(UpdateState(counter));
}
void onNumberDecrease(
NumberDecreaseEvent event, Emitter<CounterStates> emit) async {
counter = counter - 1;
emit(UpdateState(counter));
}
}

View File

@@ -0,0 +1,14 @@
class CounterEvents {}
class NumberIncreaseEvent extends CounterEvents {}
class NumberDecreaseEvent extends CounterEvents {}
class CounterStates {}
class InitialState extends CounterStates {}
class UpdateState extends CounterStates {
final int counter;
UpdateState(this.counter);
}

View 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 }

View 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);
}
}
}
}