api integration
This commit is contained in:
12
lib/features/biometric/domain/repository/biometric_api.dart
Normal file
12
lib/features/biometric/domain/repository/biometric_api.dart
Normal file
@@ -0,0 +1,12 @@
|
||||
import '../../../../Api_Helper/base_manager.dart';
|
||||
import '../../../../shared/api/api_endpoints.dart';
|
||||
import '../../../../shared/api/network_api_services.dart';
|
||||
|
||||
class BiometricAPIServices {
|
||||
BiometricAPIServices();
|
||||
Future<ResponseData> biometricLoginApi(Map<String, dynamic> data) async {
|
||||
String url = ApiEndpoints.biometricLoginapi;
|
||||
final response = await NetworkApiService().post(url, data);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,19 @@ import 'dart:io';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:local_auth/local_auth.dart';
|
||||
import 'package:tanami_app/core/utils/secure/secure_storage_service.dart';
|
||||
import 'package:tanami_app/features/biometric/domain/repository/biometric_api.dart';
|
||||
|
||||
import '../../../../Api_Helper/base_manager.dart';
|
||||
import 'biometric_event.dart';
|
||||
import 'biometric_state.dart';
|
||||
|
||||
class BiometricBloc extends Bloc<BiometricEvent, BiometricState> {
|
||||
final LocalAuthentication localAuthentication;
|
||||
final SecureStorageService secureStorageService;
|
||||
|
||||
BiometricBloc(this.localAuthentication) : super(BiometricInitial()) {
|
||||
BiometricBloc(this.localAuthentication, this.secureStorageService)
|
||||
: super(BiometricInitial()) {
|
||||
on<CheckBiometricEvent>(_onCheckBiometric);
|
||||
on<AuthenticateBiometricEvent>(_onAuthenticateBiometric);
|
||||
}
|
||||
@@ -46,7 +51,21 @@ class BiometricBloc extends Bloc<BiometricEvent, BiometricState> {
|
||||
}
|
||||
|
||||
if (authenticated) {
|
||||
emit(BiometricAuthenticated());
|
||||
Map<String, dynamic> biometricLoginData = {
|
||||
"token": await secureStorageService.read("temp_token"),
|
||||
};
|
||||
|
||||
ResponseData response =
|
||||
await BiometricAPIServices().biometricLoginApi(biometricLoginData);
|
||||
if (response.status == ResponseStatus.SUCCESS) {
|
||||
await secureStorageService.write(
|
||||
'accesstoken', response.data["data"]["accessToken"]);
|
||||
await secureStorageService.write(
|
||||
'refreshtoken', response.data["data"]["refreshToken"]);
|
||||
emit(BiometricAuthenticated());
|
||||
} else {
|
||||
emit(BiometricFailed('Authentication failed'));
|
||||
}
|
||||
} else {
|
||||
emit(BiometricFailed('Authentication failed'));
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ class BiometricLayout extends StatelessWidget {
|
||||
deviceLockedDialog(context);
|
||||
} else if (state is BiometricAuthenticated) {
|
||||
await secureStorageService.write('isLoginedIn', "true");
|
||||
// successToastMessage(context, "Authentication Successful");
|
||||
goRouter.goNamed(RouteName.mainScreen);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -30,7 +30,8 @@ class RestorePasswordBottomSection extends StatelessWidget {
|
||||
if (state is ChangePasswordLoading) {
|
||||
Loader.loader(context);
|
||||
} else if (state is ChangePasswordSuccess) {
|
||||
successToastMessage(context, "Password changed successful !");
|
||||
successToastMessage(context,
|
||||
localizations.translate(AppText.passwordChangedSucessfully));
|
||||
goRouter.pop();
|
||||
goRouter.pop();
|
||||
} else if (state is ChangePasswordFailure) {
|
||||
|
||||
@@ -27,7 +27,6 @@ class ChooseCountryLayout extends StatelessWidget {
|
||||
child: ButtonWidget().elevatedBtn(
|
||||
txtClr: AppColor.plainWhite,
|
||||
function: () {
|
||||
print("//");
|
||||
goRouter.pop();
|
||||
},
|
||||
text: localizations.translate(AppText.confirmSelectionText),
|
||||
|
||||
@@ -33,7 +33,8 @@ class RestorePasswordBottomSection extends StatelessWidget {
|
||||
if (state is RestorePasswordLoading) {
|
||||
Loader.loader(context);
|
||||
} else if (state is RestorePasswordSuccess) {
|
||||
successToastMessage(context, "Password resetted successful !");
|
||||
successToastMessage(context,
|
||||
localizations.translate(AppText.passwordResetSucessful));
|
||||
goRouter.pop();
|
||||
radioBloc.resetSelection();
|
||||
goRouter.goNamed(RouteName.loginScreen, pathParameters: {
|
||||
|
||||
@@ -35,7 +35,7 @@ class RestorePasswordForm extends StatelessWidget {
|
||||
create: (_) => PasswordVisibilityBloc(),
|
||||
child: FormLabelTextField(
|
||||
hintText: localizations.translate(AppText.enterPassword),
|
||||
title: "New Password",
|
||||
title: localizations.translate(AppText.newPasswordText),
|
||||
type: AppText.password.toLowerCase(),
|
||||
textEditingController: restorePasswordBloc.passwordTextField,
|
||||
),
|
||||
|
||||
@@ -36,7 +36,8 @@ class RestorePasswordPhoneVerificationBottomSection extends StatelessWidget {
|
||||
if (state is RestorePasswordPhoneVerificationLoading) {
|
||||
Loader.loader(context);
|
||||
} else if (state is RestorePasswordPhoneVerificationSuccess) {
|
||||
successToastMessage(context, "OTP send successful !");
|
||||
successToastMessage(context,
|
||||
localizations.translate(AppText.otpSendSuccessfulText));
|
||||
goRouter.pop();
|
||||
radioBloc.resetSelection();
|
||||
goRouter.pushNamed(RouteName.otpScreen,
|
||||
|
||||
@@ -54,6 +54,8 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
|
||||
await secureStorageService.write(
|
||||
'temp_token', response.data['data']['user']);
|
||||
emit(LoginMasterPinPending());
|
||||
} else {
|
||||
emit(LoginFailure(response.message.toString()));
|
||||
}
|
||||
} else {
|
||||
emit(const LoginFailure(
|
||||
|
||||
@@ -21,27 +21,8 @@ class OTPBloc extends Bloc<OTPEvent, OTPState> {
|
||||
} else {
|
||||
emit(OTPFailed("Oops something went wrong"));
|
||||
}
|
||||
print("//");
|
||||
} catch (e) {
|
||||
emit(OTPError("Oops something went wrong"));
|
||||
}
|
||||
}
|
||||
|
||||
/* Future<void> VerifyOTPCall(
|
||||
GetCountry event, Emitter<GetCountryState> emit) async {
|
||||
if (event is GetCountry) {
|
||||
emit(CountryLoading());
|
||||
try {
|
||||
ResponseData response = await GetCountryAPI().getcountryAPI();
|
||||
if (response.status == ResponseStatus.SUCCESS) {
|
||||
GetCountryModel countryModel =
|
||||
GetCountryModel.fromJson(response.data);
|
||||
emit(CountryLoaded(countryModel));
|
||||
}
|
||||
print("//");
|
||||
} catch (e) {
|
||||
emit(CountryError("Oops Something went wrong"));
|
||||
}
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
||||
@@ -33,21 +33,19 @@ class ResendOtpSection extends StatelessWidget {
|
||||
loginBloc.phoneNumberTextField.text = Globalconst.phonenumber;
|
||||
loginBloc.countrySelectionTextField.text = Globalconst.name;
|
||||
var localizations = AppLocalizations.of(context);
|
||||
final SecureStorageService secureStorageService = SecureStorageService();
|
||||
return BlocBuilder<TimerBloc, TimerState>(
|
||||
builder: (context, state) {
|
||||
builder: (context, timerState) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
TextWidget().text14W500(
|
||||
state.formattedDuration,
|
||||
timerState.formattedDuration,
|
||||
clr: AppColor.plainBlack,
|
||||
),
|
||||
BlocConsumer<RegisterBloc, RegisterState>(
|
||||
listener: (context, state) {
|
||||
print(loginBloc.state);
|
||||
if (state is RegisterLoading) {
|
||||
Loader.loader(context);
|
||||
} else if (state is RegisterSuccess) {
|
||||
@@ -72,12 +70,14 @@ class ResendOtpSection extends StatelessWidget {
|
||||
}
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
loginBloc.add(
|
||||
Resendotp(token),
|
||||
);
|
||||
print("///");
|
||||
|
||||
// successToastMessage(context, "OTP Resend Sucessfully !");
|
||||
if (timerState is TimerRunComplete) {
|
||||
loginBloc.add(
|
||||
Resendotp(token),
|
||||
);
|
||||
} else {
|
||||
errorToastMessage(context,
|
||||
"Please wait ${timerState.formattedDuration} Minutes before resending OTP");
|
||||
}
|
||||
},
|
||||
child: TextWidget().text14W500(
|
||||
localizations.translate(AppText.resendSms),
|
||||
@@ -89,24 +89,6 @@ class ResendOtpSection extends StatelessWidget {
|
||||
);
|
||||
},
|
||||
),
|
||||
/* GestureDetector(
|
||||
onTap: () {
|
||||
regbloc.add(
|
||||
RegisterSubmitted(
|
||||
loginBloc.phoneNumberTextField.text,
|
||||
loginBloc.countrySelectionTextField.text,
|
||||
loginBloc.isdcode
|
||||
),
|
||||
);
|
||||
print("///");
|
||||
// successToastMessage(context, "OTP Resend Sucessfully !");
|
||||
},
|
||||
child: TextWidget().text14W500(
|
||||
localizations.translate(AppText.resendSms),
|
||||
clr: AppColor.plainBlack,
|
||||
textDecoration: TextDecoration.underline,
|
||||
),
|
||||
) */
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -53,7 +53,7 @@ class RegisterBloc extends Bloc<RegisterEvent, RegisterState> {
|
||||
emit(RegisterLoading());
|
||||
try {
|
||||
Map<String, dynamic> requestdata = {
|
||||
"token": secureStorageService.read('temp_token'),
|
||||
"token": await secureStorageService.read('temp_token'),
|
||||
};
|
||||
ResponseData response = await OTPAPI().resendOTPRequest(requestdata);
|
||||
if (response.status == ResponseStatus.SUCCESS) {
|
||||
|
||||
@@ -39,11 +39,11 @@ class RegisterBottomSection extends StatelessWidget {
|
||||
const Gap(36),
|
||||
BlocConsumer<RegisterBloc, RegisterState>(
|
||||
listener: (context, state) {
|
||||
print(loginBloc.state);
|
||||
if (state is RegisterLoading) {
|
||||
Loader.loader(context);
|
||||
} else if (state is RegisterSuccess) {
|
||||
successToastMessage(context, "successful !");
|
||||
successToastMessage(
|
||||
context, localizations.translate(AppText.successfulText));
|
||||
goRouter.pop();
|
||||
|
||||
goRouter.pushNamed(RouteName.otpScreen,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:tanami_app/features/welcome/presentation/pages/welcome_layout.dart';
|
||||
|
||||
import '../../../../core/styles/app_color.dart';
|
||||
import '../../../../shared/components/exit_app_dialog.dart';
|
||||
import '../bloc/onboarding_bloc.dart';
|
||||
|
||||
class WelcomeScreen extends StatelessWidget {
|
||||
@@ -10,17 +11,23 @@ class WelcomeScreen extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColor.plainWhite,
|
||||
body: MultiBlocProvider(
|
||||
// Define the providers for the OnboardingBloc and other blocs
|
||||
providers: [
|
||||
BlocProvider(
|
||||
// Create an instance of the OnboardingBloc
|
||||
create: (_) => OnboardingBloc(),
|
||||
),
|
||||
],
|
||||
child: WelcomeLayout(),
|
||||
return WillPopScope(
|
||||
onWillPop: () async {
|
||||
exitAppDialog(context);
|
||||
return false;
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: AppColor.plainWhite,
|
||||
body: MultiBlocProvider(
|
||||
// Define the providers for the OnboardingBloc and other blocs
|
||||
providers: [
|
||||
BlocProvider(
|
||||
// Create an instance of the OnboardingBloc
|
||||
create: (_) => OnboardingBloc(),
|
||||
),
|
||||
],
|
||||
child: WelcomeLayout(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user