api integration
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:equatable/equatable.dart';
|
||||
import 'package:tanami_app/Api_Helper/base_manager.dart';
|
||||
import 'package:tanami_app/core/styles/app_text.dart';
|
||||
|
||||
import '../../../../core/routes/routes.dart';
|
||||
import '../../../../core/utils/secure/secure_storage_service.dart';
|
||||
import '../../Repository/PinAPIServices.dart';
|
||||
|
||||
@@ -71,6 +72,7 @@ class PinBloc extends Bloc<PinEvent, PinState> {
|
||||
});
|
||||
|
||||
on<VerifyPinPressed>((event, emit) async {
|
||||
emit(const PinLoading());
|
||||
final storedPin = await secureStorageService.read('pin_code');
|
||||
Map<String, dynamic> pindata = {
|
||||
"token": await secureStorageService.read("temp_token"),
|
||||
@@ -82,8 +84,13 @@ class PinBloc extends Bloc<PinEvent, PinState> {
|
||||
await secureStorageService.write('userMPIN', storedPin.toString());
|
||||
}
|
||||
|
||||
emit(state.copyWith(isVerified: true, error: '', verifiedOnce: true));
|
||||
emit(state.copyWith(
|
||||
isVerified: true,
|
||||
error: '',
|
||||
verifiedOnce: true,
|
||||
pinComplete: true));
|
||||
} else {
|
||||
goRouter.pop();
|
||||
emit(state.copyWith(
|
||||
isVerified: false,
|
||||
error: AppText.incorrectPinCode,
|
||||
@@ -93,6 +100,7 @@ class PinBloc extends Bloc<PinEvent, PinState> {
|
||||
});
|
||||
|
||||
on<VerifyLoginPinPressed>((event, emit) async {
|
||||
emit(const PinLoading());
|
||||
Map<String, dynamic> pindata = {
|
||||
"token": await secureStorageService.read("temp_token"),
|
||||
"masterPin": event.pin
|
||||
@@ -100,6 +108,10 @@ class PinBloc extends Bloc<PinEvent, PinState> {
|
||||
|
||||
ResponseData response = await PinAPIServices().Verifypin(pindata);
|
||||
if (response.status == ResponseStatus.SUCCESS) {
|
||||
await secureStorageService.write(
|
||||
'accesstoken', response.data["data"]["accessToken"]);
|
||||
await secureStorageService.write(
|
||||
'refreshtoken', response.data["data"]["refreshToken"]);
|
||||
emit(state.copyWith(
|
||||
pinComplete: true,
|
||||
pin: state.pin,
|
||||
@@ -107,6 +119,7 @@ class PinBloc extends Bloc<PinEvent, PinState> {
|
||||
error: '',
|
||||
verifiedOnce: false));
|
||||
} else {
|
||||
goRouter.pop();
|
||||
emit(state.copyWith(
|
||||
pinComplete: true,
|
||||
pin: state.pin,
|
||||
|
||||
@@ -34,3 +34,13 @@ class PinState extends Equatable {
|
||||
@override
|
||||
List<Object> get props => [pin, pinComplete, isVerified, error, verifiedOnce];
|
||||
}
|
||||
|
||||
class PinLoading extends PinState {
|
||||
const PinLoading()
|
||||
: super(
|
||||
pin: '',
|
||||
pinComplete: false,
|
||||
isVerified: false,
|
||||
error: '',
|
||||
verifiedOnce: false);
|
||||
}
|
||||
|
||||
@@ -4,9 +4,13 @@ import 'package:gap/gap.dart';
|
||||
import 'package:tanami_app/core/routes/route_name.dart';
|
||||
import 'package:tanami_app/core/routes/routes.dart';
|
||||
import 'package:tanami_app/core/styles/app_color.dart';
|
||||
import 'package:tanami_app/core/styles/app_text.dart';
|
||||
import 'package:tanami_app/core/utils/secure/secure_storage_service.dart';
|
||||
import 'package:tanami_app/shared/components/text_widget.dart';
|
||||
import 'package:tanami_app/shared/components/toast_message.dart';
|
||||
|
||||
import '../../../../core/utils/language/localizations_delegate.dart';
|
||||
import '../../../../shared/components/loader.dart';
|
||||
import '../bloc/pin_bloc.dart';
|
||||
|
||||
class ConfirmPinKey extends StatelessWidget {
|
||||
@@ -14,13 +18,22 @@ class ConfirmPinKey extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var localizations = AppLocalizations.of(context);
|
||||
final SecureStorageService secureStorageService = SecureStorageService();
|
||||
return Column(
|
||||
children: [
|
||||
const Gap(20),
|
||||
BlocConsumer<PinBloc, PinState>(
|
||||
listener: (context, state) async {
|
||||
if (state is PinLoading) {
|
||||
Loader.loader(context);
|
||||
}
|
||||
if (state.pinComplete && state.isVerified) {
|
||||
goRouter.pop();
|
||||
successToastMessage(
|
||||
context,
|
||||
localizations
|
||||
.translate(AppText.masterPinAddedSucessfullyText));
|
||||
await secureStorageService.write('isLoginedIn', "true");
|
||||
goRouter.goNamed(RouteName.mainScreen);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import 'package:tanami_app/shared/components/text_widget.dart';
|
||||
import '../../../../core/routes/route_name.dart';
|
||||
import '../../../../core/routes/routes.dart';
|
||||
import '../../../../core/utils/language/localizations_delegate.dart';
|
||||
import '../../../../shared/components/loader.dart';
|
||||
import '../../../../shared/components/toast_message.dart';
|
||||
import '../../../login/presentation/bloc/login_bloc.dart';
|
||||
import '../bloc/pin_bloc.dart';
|
||||
@@ -32,10 +33,14 @@ class PinKey extends StatelessWidget {
|
||||
const Gap(20),
|
||||
BlocConsumer<PinBloc, PinState>(
|
||||
listener: (context, state) {
|
||||
if (state is PinLoading) {
|
||||
Loader.loader(context);
|
||||
}
|
||||
if (state.pinComplete &&
|
||||
state.error.isEmpty &&
|
||||
!state.verifiedOnce) {
|
||||
if (fromScreen == "login" || fromScreen == "LoginedInUser") {
|
||||
goRouter.pop();
|
||||
loginBloc.resetFields();
|
||||
radioBloc.resetSelection();
|
||||
successToastMessage(context,
|
||||
@@ -46,10 +51,12 @@ class PinKey extends StatelessWidget {
|
||||
context, localizations.translate(AppText.pinUpdatedSucess));
|
||||
goRouter.pop();
|
||||
} else {
|
||||
goRouter.pop();
|
||||
context.read<PinBloc>().add(SavePinPressed());
|
||||
goRouter.pushNamed(RouteName.confirmPinScreen);
|
||||
}
|
||||
} else {
|
||||
// goRouter.pop();
|
||||
if (state.pinComplete) {
|
||||
errorToastMessage(
|
||||
context,
|
||||
|
||||
Reference in New Issue
Block a user