io api settings api

This commit is contained in:
jayesh
2024-07-25 19:19:25 +05:30
parent bc15d0b1b3
commit 9b44dc0cf3
67 changed files with 2871 additions and 394 deletions

View File

@@ -1,6 +1,12 @@
import 'dart:io';
import 'package:bloc/bloc.dart';
import 'package:tanami_app/core/utils/secure/secure_storage_service.dart';
import '../../../../Api_Helper/base_manager.dart';
import '../../../../core/utils/device_info/device_info_data.dart';
import '../../../../features/MainScreens/Settings/domain/repository/settings_api.dart';
import '../../../../features/register/Repository/RegisterApi.dart';
import 'toggle_event.dart';
import 'toggle_state.dart';
@@ -16,11 +22,75 @@ class ToggleBloc extends Bloc<ToggleEvent, ToggleState> {
void _onToggleSwitch(ToggleSwitch event, Emitter<ToggleState> emit) async {
if (state is ToggleOn) {
emit(ToggleOff());
await secureStorageService.write(type, 'off');
if (type == "biometric") {
emit(ToggleOff());
Map<String, dynamic> biometricdata = {
"code": await secureStorageService.read("temp_token"),
"is_2FA_on": false,
"deviceId": await DeviceInfoData().getDeviceId(),
"biometric_type": Platform.isIOS ? "face" : "fingerprint"
};
ResponseData response =
await RegisterAPIService().BiometricUpdate(biometricdata);
if (response.status == ResponseStatus.SUCCESS) {
await secureStorageService.write(type, 'off');
await secureStorageService.write("biometric", 'of');
} else {
emit(ToggleOn());
await secureStorageService.write(type, 'on');
}
} else if (type == "notification") {
emit(ToggleOff());
ResponseData response = await SettingsApi().updateNotification();
if (response.status == ResponseStatus.SUCCESS) {
await secureStorageService.write(type, 'off');
await secureStorageService.write("notification", 'of');
} else {
emit(ToggleOn());
await secureStorageService.write(type, 'on');
}
} else {
emit(ToggleOff());
await secureStorageService.write(type, 'off');
}
} else {
emit(ToggleOn());
await secureStorageService.write(type, 'on');
if (type == "biometric") {
emit(ToggleOn());
Map<String, dynamic> biometricdata = {
"code": await secureStorageService.read("temp_token"),
"is_2FA_on": true,
"deviceId": await DeviceInfoData().getDeviceId(),
"biometric_type": Platform.isIOS ? "face" : "fingerprint"
};
ResponseData response =
await RegisterAPIService().BiometricUpdate(biometricdata);
if (response.status == ResponseStatus.SUCCESS) {
await secureStorageService.write("biometric", 'on');
await secureStorageService.write(type, 'on');
} else {
emit(ToggleOff());
await secureStorageService.write(type, 'off');
}
} else if (type == "notification") {
emit(ToggleOn());
ResponseData response = await SettingsApi().updateNotification();
if (response.status == ResponseStatus.SUCCESS) {
await secureStorageService.write(type, 'on');
await secureStorageService.write("notification", 'on');
} else {
emit(ToggleOff());
await secureStorageService.write(type, 'off');
}
} else {
emit(ToggleOn());
await secureStorageService.write(type, 'on');
}
}
}