api integration

This commit is contained in:
jayesh
2024-07-19 16:20:14 +05:30
parent 948777ee21
commit 4e768e6f6a
44 changed files with 166 additions and 113 deletions

View File

@@ -1,6 +1,7 @@
import 'package:bloc/bloc.dart';
import '../../../Api_Helper/base_manager.dart';
import '../../../Globalconst.dart';
import '../domain/Repository/otp_api.dart';
import 'otp_event.dart';
import 'otp_state.dart';
@@ -19,10 +20,12 @@ class OTPBloc extends Bloc<OTPEvent, OTPState> {
if (response.status == ResponseStatus.SUCCESS) {
emit(OTPLoaded());
} else {
emit(OTPFailed("Oops something went wrong"));
emit(OTPFailed(response.message.toString()));
}
} catch (e) {
emit(OTPError("Oops something went wrong"));
emit(OTPError(Globalconst.languageSelected == "en"
? "تبا شيء ما حدث بشكل خاطئ"
: ""));
}
}
}

View File

@@ -1,6 +1,7 @@
// timer_bloc.dart
import 'dart:async';
import 'package:bloc/bloc.dart';
import 'timer_event.dart';
import 'timer_state.dart';
@@ -13,7 +14,7 @@ class TimerBloc extends Bloc<TimerEvent, TimerState> {
}
void _onStartTimer(StartTimer event, Emitter<TimerState> emit) {
const int duration = 300; // 5 minutes in seconds
const int duration = 30; // 5 minutes in seconds
emit(const TimerRunInProgress(duration));
_startTicker(duration);
}

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:sms_autofill/sms_autofill.dart';
@@ -63,6 +64,8 @@ class OtpFillSection extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
PinFieldAutoFill(
keyboardType: TextInputType.number,
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
controller: otpBloc.otpController,
currentCode: otpBloc.otpController.text,
decoration: BoxLooseDecoration(

View File

@@ -14,6 +14,7 @@ import '../../../register/presentation/bloc/register_bloc.dart';
import '../../../register/presentation/bloc/register_event.dart';
import '../../../register/presentation/bloc/register_state.dart';
import '../bloc/timer/timer_bloc.dart';
import '../bloc/timer/timer_event.dart';
import '../bloc/timer/timer_state.dart';
class ResendOtpSection extends StatelessWidget {
@@ -49,6 +50,7 @@ class ResendOtpSection extends StatelessWidget {
if (state is RegisterLoading) {
Loader.loader(context);
} else if (state is RegisterSuccess) {
context.read<TimerBloc>().add(StartTimer()); // Reset timer
successToastMessage(context, "OTP Resend Sucessfully !");
goRouter.pop();
} else if (state is RegisterFailure) {
@@ -75,13 +77,13 @@ class ResendOtpSection extends StatelessWidget {
Resendotp(token),
);
} else {
errorToastMessage(context,
"Please wait ${timerState.formattedDuration} Minutes before resending OTP");
// errorToastMessage(context,
// "Please wait ${timerState.formattedDuration} Seconds before resending OTP");
}
},
child: TextWidget().text14W500(
localizations.translate(AppText.resendSms),
clr: isButtonEnabled
clr: timerState is TimerRunComplete
? AppColor.plainBlack
: AppColor.indicatorInactiveColor,
textDecoration: TextDecoration.underline,