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