From 57b29abf747bcb81342daa1685f84631444bbc48 Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Tue, 25 Jun 2024 15:44:00 +0300 Subject: [PATCH] Bug fixes and removed the unused code in the auth cubit --- lib/features/auth/bloc/auth_cubit.dart | 31 +++-------- lib/features/auth/view/check_email_page.dart | 54 +++++++------------- 2 files changed, 27 insertions(+), 58 deletions(-) diff --git a/lib/features/auth/bloc/auth_cubit.dart b/lib/features/auth/bloc/auth_cubit.dart index 3419b5a..7715b3a 100644 --- a/lib/features/auth/bloc/auth_cubit.dart +++ b/lib/features/auth/bloc/auth_cubit.dart @@ -29,14 +29,12 @@ class AuthCubit extends Cubit { String otpCode = ''; final loginFormKey = GlobalKey(); final signUpFormKey = GlobalKey(); - final checkemailFormKey = GlobalKey(); + final checkEmailFormKey = GlobalKey(); final createNewPasswordKey = GlobalKey(); bool isPasswordVisible = false; bool showValidationMessage = false; - static GlobalKey formKey = GlobalKey(); - void changePasswordVisibility() { isPasswordVisible = !isPasswordVisible; emit(AuthPasswordVisibilityChanged()); @@ -103,9 +101,6 @@ class AuthCubit extends Cubit { String? reEnterPasswordCheck(String? value) { passwordValidator(value); if (signUpPassword == value) { - // if (signUpFormKey.currentState != null) { - // signUpFormKey.currentState!.save(); - // } return null; } else { return 'Passwords do not match'; @@ -115,9 +110,6 @@ class AuthCubit extends Cubit { String? reEnterPasswordCheckForgetPass(String? value) { passwordValidator(value); if (newPassword == value) { - // if (signUpFormKey.currentState != null) { - // signUpFormKey.currentState!.save(); - // } return null; } else { return 'Passwords do not match'; @@ -245,24 +237,21 @@ class AuthCubit extends Cubit { } } - verifyOtp(bool isForgotPass ) async { + verifyOtp(bool isForgotPass) async { emit(AuthLoginLoading()); try { final response = await AuthenticationAPI.verifyPassCode( body: {'email': email, 'type': 'VERIFICATION', 'otpCode': otpCode}); if (response['statusCode'] == 200) { - emailController.text = email; - passwordController.text = signUpPassword; - isForgotPass?(){}: await login(); + if (!isForgotPass) { + emailController.text = email; + passwordController.text = signUpPassword; + await login(); + } emit(AuthOtpSuccess()); } else { emit(AuthLoginError(message: 'Something went wrong')); } - // if (otpCode == '654321') { - // emit(AuthOtpSuccess()); - // } else { - // emit(AuthLoginError(message: 'Otp is not correct')); - // } } catch (failure) { emit(AuthLoginError(message: failure.toString())); return; @@ -324,14 +313,10 @@ class AuthCubit extends Cubit { sendToForgetPassword({required String password}) async { try { emit(AuthForgetPassLoading()); - await AuthenticationAPI.forgetPassword(email:email ,password: password); + await AuthenticationAPI.forgetPassword(email: email, password: password); emit(AuthForgetPassSuccess()); } catch (_) { emit(AuthForgetPassError(message: 'Something went wrong')); } } - - - - } diff --git a/lib/features/auth/view/check_email_page.dart b/lib/features/auth/view/check_email_page.dart index 0812bb8..63fc691 100644 --- a/lib/features/auth/view/check_email_page.dart +++ b/lib/features/auth/view/check_email_page.dart @@ -14,16 +14,14 @@ import 'package:syncrow_app/utils/resource_manager/constants.dart'; import 'package:syncrow_app/utils/resource_manager/font_manager.dart'; import 'package:syncrow_app/utils/resource_manager/styles_manager.dart'; - class checkEmailPage extends StatelessWidget { const checkEmailPage({super.key}); @override Widget build(BuildContext context) { - final formKey = AuthCubit.get(context).checkemailFormKey; + final formKey = AuthCubit.get(context).checkEmailFormKey; SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle( - statusBarBrightness: Brightness.light, - statusBarIconBrightness: Brightness.light)); + statusBarBrightness: Brightness.light, statusBarIconBrightness: Brightness.light)); return BlocConsumer( listener: (context, state) { if (state is AuthError) { @@ -93,9 +91,7 @@ class checkEmailPage extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ SizedBox( - height: - MediaQuery.sizeOf(context).height / - 5.5, + height: MediaQuery.sizeOf(context).height / 5.5, ), TitleMedium( text: 'Forgot password?', @@ -117,39 +113,32 @@ class checkEmailPage extends StatelessWidget { scrollPadding: EdgeInsets.zero, autocorrect: false, enableSuggestions: false, - autofillHints: const [ - AutofillHints.email - ], - validator: AuthCubit.get(context) - .emailAddressValidator, + autofillHints: const [AutofillHints.email], + validator: AuthCubit.get(context).emailAddressValidator, onTapOutside: (event) { FocusScope.of(context).unfocus(); }, onChanged: (value) { AuthCubit.get(context).email = value; }, - decoration: defaultInputDecoration( - context, + decoration: defaultInputDecoration(context, hint: "Example@email.com"), ), const SizedBox( height: 20, ), Row( - mainAxisAlignment: - MainAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, children: [ Expanded( child: DefaultButton( isDone: state is AuthLoginSuccess, isLoading: state is AuthLoading, customButtonStyle: ButtonStyle( - backgroundColor: - MaterialStateProperty.all( + backgroundColor: MaterialStateProperty.all( Colors.black.withOpacity(.25), ), - foregroundColor: - MaterialStateProperty.all( + foregroundColor: MaterialStateProperty.all( Colors.white, ), ), @@ -157,15 +146,11 @@ class checkEmailPage extends StatelessWidget { 'Send Code', ), onPressed: () { - AuthCubit.get(context) - .showValidationMessage = true; - if (formKey.currentState! - .validate()) { + AuthCubit.get(context).showValidationMessage = true; + if (formKey.currentState!.validate()) { if ((state is! AuthLoading)) { - AuthCubit.get(context) - .sendOtp(); - FocusScope.of(context) - .unfocus(); + AuthCubit.get(context).sendOtp(); + FocusScope.of(context).unfocus(); } } }, @@ -174,15 +159,15 @@ class checkEmailPage extends StatelessWidget { ], ), Padding( - padding: EdgeInsets.only(top: MediaQuery.sizeOf(context).height/5.5), + padding: EdgeInsets.only( + top: MediaQuery.sizeOf(context).height / 5.5), child: Row( - mainAxisAlignment: - MainAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, children: [ BodyLarge( text: "Do you have an account? ", - style: context.displaySmall - .copyWith(color: Colors.white), + style: + context.displaySmall.copyWith(color: Colors.white), ), TextButton( onPressed: () { @@ -190,8 +175,7 @@ class checkEmailPage extends StatelessWidget { }, child: BodyLarge( text: "Sign in", - style: - context.displaySmall.copyWith( + style: context.displaySmall.copyWith( color: Colors.black, fontWeight: FontsManager.bold, ),