Removed prints and warnings

This commit is contained in:
Abdullah Alassaf
2024-09-08 23:09:45 +03:00
parent f6cc19cad7
commit 1f22e5d322
2 changed files with 31 additions and 55 deletions

View File

@ -31,8 +31,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
////////////////////////////// forget password ////////////////////////////////// ////////////////////////////// forget password //////////////////////////////////
final TextEditingController forgetEmailController = TextEditingController(); final TextEditingController forgetEmailController = TextEditingController();
final TextEditingController forgetPasswordController = final TextEditingController forgetPasswordController = TextEditingController();
TextEditingController();
final TextEditingController forgetOtp = TextEditingController(); final TextEditingController forgetOtp = TextEditingController();
final forgetFormKey = GlobalKey<FormState>(); final forgetFormKey = GlobalKey<FormState>();
late bool checkValidate = false; late bool checkValidate = false;
@ -41,16 +40,13 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
int _remainingTime = 0; int _remainingTime = 0;
List<RegionModel>? regionList = [RegionModel(name: 'name', id: 'id')]; List<RegionModel>? regionList = [RegionModel(name: 'name', id: 'id')];
Future _onStartTimer(StartTimerEvent event, Emitter<AuthState> emit) async {
Future _onStartTimer(
StartTimerEvent event, Emitter<AuthState> emit) async {
if (_validateInputs(emit)) return; if (_validateInputs(emit)) return;
if (_timer != null && _timer!.isActive) { if (_timer != null && _timer!.isActive) {
return; return;
} }
_remainingTime = 1; _remainingTime = 1;
add(UpdateTimerEvent( add(UpdateTimerEvent(remainingTime: _remainingTime, isButtonEnabled: false));
remainingTime: _remainingTime, isButtonEnabled: false));
try { try {
forgetEmailValidate = ''; forgetEmailValidate = '';
_remainingTime = (await AuthenticationAPI.sendOtp( _remainingTime = (await AuthenticationAPI.sendOtp(
@ -59,13 +55,12 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
if (e.response!.statusCode == 400) { if (e.response!.statusCode == 400) {
final errorData = e.response!.data; final errorData = e.response!.data;
String errorMessage = errorData['message']; String errorMessage = errorData['message'];
print('sendOtp=$errorMessage');
if (errorMessage == 'User not found') { if (errorMessage == 'User not found') {
validate='Invalid Credential'; validate = 'Invalid Credential';
emit(AuthInitialState()); emit(AuthInitialState());
return 1; return 1;
} else { } else {
validate=''; validate = '';
_remainingTime = errorData['data']['cooldown'] ?? 1; _remainingTime = errorData['data']['cooldown'] ?? 1;
emit(AuthInitialState()); emit(AuthInitialState());
} }
@ -75,7 +70,6 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
return 1; return 1;
} }
emit(AuthInitialState()); emit(AuthInitialState());
} catch (e) { } catch (e) {
emit(AuthInitialState()); emit(AuthInitialState());
@ -88,8 +82,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
_timer?.cancel(); _timer?.cancel();
add(const UpdateTimerEvent(remainingTime: 0, isButtonEnabled: true)); add(const UpdateTimerEvent(remainingTime: 0, isButtonEnabled: true));
} else { } else {
add(UpdateTimerEvent( add(UpdateTimerEvent(remainingTime: _remainingTime, isButtonEnabled: false));
remainingTime: _remainingTime, isButtonEnabled: false));
} }
}); });
} }
@ -99,16 +92,14 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
emit(const TimerState(isButtonEnabled: true, remainingTime: 0)); emit(const TimerState(isButtonEnabled: true, remainingTime: 0));
} }
Future<void> changePassword( Future<void> changePassword(ChangePasswordEvent event, Emitter<AuthState> emit) async {
ChangePasswordEvent event, Emitter<AuthState> emit) async {
try { try {
emit(LoadingForgetState()); emit(LoadingForgetState());
var response = await AuthenticationAPI.verifyOtp( var response = await AuthenticationAPI.verifyOtp(
email: forgetEmailController.text, otpCode: forgetOtp.text); email: forgetEmailController.text, otpCode: forgetOtp.text);
if (response == true) { if (response == true) {
await AuthenticationAPI.forgetPassword( await AuthenticationAPI.forgetPassword(
password: forgetPasswordController.text, password: forgetPasswordController.text, email: forgetEmailController.text);
email: forgetEmailController.text);
_timer?.cancel(); _timer?.cancel();
emit(const TimerState(isButtonEnabled: true, remainingTime: 0)); emit(const TimerState(isButtonEnabled: true, remainingTime: 0));
emit(SuccessForgetState()); emit(SuccessForgetState());
@ -125,12 +116,10 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
} else if (errorMessage == "OTP expired") { } else if (errorMessage == "OTP expired") {
forgetValidate = 'One time password has been expired.'; forgetValidate = 'One time password has been expired.';
emit(AuthInitialState()); emit(AuthInitialState());
}else{ } else {
validate=''; validate = '';
emit(AuthInitialState()); emit(AuthInitialState());
} }
} }
} }
@ -142,9 +131,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
} }
void _onUpdateTimer(UpdateTimerEvent event, Emitter<AuthState> emit) { void _onUpdateTimer(UpdateTimerEvent event, Emitter<AuthState> emit) {
emit(TimerState( emit(TimerState(isButtonEnabled: event.isButtonEnabled, remainingTime: event.remainingTime));
isButtonEnabled: event.isButtonEnabled,
remainingTime: event.remainingTime));
} }
///////////////////////////////////// login ///////////////////////////////////// ///////////////////////////////////// login /////////////////////////////////////
@ -176,9 +163,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
token = await AuthenticationAPI.loginWithEmail( token = await AuthenticationAPI.loginWithEmail(
model: LoginWithEmailModel( model: LoginWithEmailModel(
email: event.username, email: event.username, password: event.password, regionUuid: event.regionUuid),
password: event.password,
regionUuid: event.regionUuid),
); );
} catch (failure) { } catch (failure) {
validate = 'Invalid Credentials!'; validate = 'Invalid Credentials!';
@ -188,8 +173,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
if (token.accessTokenIsNotEmpty) { if (token.accessTokenIsNotEmpty) {
FlutterSecureStorage storage = const FlutterSecureStorage(); FlutterSecureStorage storage = const FlutterSecureStorage();
await storage.write( await storage.write(key: Token.loginAccessTokenKey, value: token.accessToken);
key: Token.loginAccessTokenKey, value: token.accessToken);
const FlutterSecureStorage().write( const FlutterSecureStorage().write(
key: UserModel.userUuidKey, key: UserModel.userUuidKey,
value: Token.decodeToken(token.accessToken)['uuid'].toString()); value: Token.decodeToken(token.accessToken)['uuid'].toString());
@ -207,9 +191,9 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
} }
checkBoxToggle( checkBoxToggle(
CheckBoxEvent event, CheckBoxEvent event,
Emitter<AuthState> emit, Emitter<AuthState> emit,
) { ) {
emit(AuthLoading()); emit(AuthLoading());
isChecked = event.newValue!; isChecked = event.newValue!;
add(CheckEnableEvent()); add(CheckEnableEvent());
@ -346,14 +330,12 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
static Future<String> getTokenAndValidate() async { static Future<String> getTokenAndValidate() async {
try { try {
const storage = FlutterSecureStorage(); const storage = FlutterSecureStorage();
final firstLaunch = await SharedPreferencesHelper.readBoolFromSP( final firstLaunch =
StringsManager.firstLaunch) ?? await SharedPreferencesHelper.readBoolFromSP(StringsManager.firstLaunch) ?? true;
true;
if (firstLaunch) { if (firstLaunch) {
storage.deleteAll(); storage.deleteAll();
} }
await SharedPreferencesHelper.saveBoolToSP( await SharedPreferencesHelper.saveBoolToSP(StringsManager.firstLaunch, false);
StringsManager.firstLaunch, false);
final value = await storage.read(key: Token.loginAccessTokenKey) ?? ''; final value = await storage.read(key: Token.loginAccessTokenKey) ?? '';
if (value.isEmpty) { if (value.isEmpty) {
return 'Token not found'; return 'Token not found';
@ -405,9 +387,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
final String formattedTime = [ final String formattedTime = [
if (days > 0) '${days}d', // Append 'd' for days if (days > 0) '${days}d', // Append 'd' for days
if (days > 0 || hours > 0) if (days > 0 || hours > 0)
hours hours.toString().padLeft(2, '0'), // Show hours if there are days or hours
.toString()
.padLeft(2, '0'), // Show hours if there are days or hours
minutes.toString().padLeft(2, '0'), minutes.toString().padLeft(2, '0'),
seconds.toString().padLeft(2, '0'), seconds.toString().padLeft(2, '0'),
].join(':'); ].join(':');
@ -416,9 +396,9 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
} }
bool checkEnable( bool checkEnable(
CheckEnableEvent event, CheckEnableEvent event,
Emitter<AuthState> emit, Emitter<AuthState> emit,
) { ) {
emit(AuthLoading()); emit(AuthLoading());
checkValidate = isChecked == true && checkValidate = isChecked == true &&
loginPasswordController.text.isNotEmpty && loginPasswordController.text.isNotEmpty &&
@ -429,18 +409,18 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
} }
changeValidate( changeValidate(
ChangeValidateEvent event, ChangeValidateEvent event,
Emitter<AuthState> emit, Emitter<AuthState> emit,
) { ) {
emit(AuthLoading()); emit(AuthLoading());
validate = ''; validate = '';
emit(LoginInitial()); emit(LoginInitial());
} }
changeForgetValidate( changeForgetValidate(
ChangeValidateEvent event, ChangeValidateEvent event,
Emitter<AuthState> emit, Emitter<AuthState> emit,
) { ) {
emit(AuthLoading()); emit(AuthLoading());
forgetValidate = ''; forgetValidate = '';
emit(LoginInitial()); emit(LoginInitial());

View File

@ -33,7 +33,6 @@ class DevicesManagementApi {
path: ApiEndpoints.getDeviceStatus.replaceAll('{uuid}', uuid), path: ApiEndpoints.getDeviceStatus.replaceAll('{uuid}', uuid),
showServerMessage: true, showServerMessage: true,
expectedResponseModel: (json) { expectedResponseModel: (json) {
print('getDeviceStatus$json');
return DeviceStatus.fromJson(json); return DeviceStatus.fromJson(json);
}, },
); );
@ -66,8 +65,7 @@ class DevicesManagementApi {
} }
} }
static Future<List<DeviceModel>> getDevicesByGatewayId( static Future<List<DeviceModel>> getDevicesByGatewayId(String gatewayId) async {
String gatewayId) async {
final response = await HTTPService().get( final response = await HTTPService().get(
path: ApiEndpoints.gatewayApi.replaceAll('{gatewayUuid}', gatewayId), path: ApiEndpoints.gatewayApi.replaceAll('{gatewayUuid}', gatewayId),
showServerMessage: false, showServerMessage: false,
@ -98,9 +96,7 @@ class DevicesManagementApi {
static Future<DeviceReport> getDeviceReports(String uuid, String code) async { static Future<DeviceReport> getDeviceReports(String uuid, String code) async {
final response = await HTTPService().get( final response = await HTTPService().get(
path: ApiEndpoints.getDeviceLogs path: ApiEndpoints.getDeviceLogs.replaceAll('{uuid}', uuid).replaceAll('{code}', code),
.replaceAll('{uuid}', uuid)
.replaceAll('{code}', code),
showServerMessage: false, showServerMessage: false,
expectedResponseModel: (json) { expectedResponseModel: (json) {
return DeviceReport.fromJson(json); return DeviceReport.fromJson(json);