From 24c7bcef55c458d3705efc53a31f310e887e08d3 Mon Sep 17 00:00:00 2001 From: Rafeek-Khoudare Date: Thu, 10 Jul 2025 16:52:34 +0300 Subject: [PATCH] PR requests --- .../widgets/securty/bloc/security_bloc.dart | 7 +- .../delete_account/delete_account_page.dart | 68 ++++---- .../securty/view/change_password_page.dart | 4 +- .../widgets/securty/view/securty_view.dart | 165 +++++------------- lib/services/api/authentication_api.dart | 16 +- 5 files changed, 97 insertions(+), 163 deletions(-) diff --git a/lib/features/menu/view/widgets/securty/bloc/security_bloc.dart b/lib/features/menu/view/widgets/securty/bloc/security_bloc.dart index 43b782e..5048a0f 100644 --- a/lib/features/menu/view/widgets/securty/bloc/security_bloc.dart +++ b/lib/features/menu/view/widgets/securty/bloc/security_bloc.dart @@ -201,11 +201,8 @@ class SecurityBloc extends Bloc { try { await AuthenticationAPI.deleteAccount(); emit(ChangedPassState()); - } on DioException catch (e) { - final errorData = e.response!.data; - String errorMessage = - errorData['error']['message'] ?? 'something went wrong'; - validate = errorMessage; + } catch (e) { + validate = e.toString(); emit(AuthInitialState()); } } diff --git a/lib/features/menu/view/widgets/securty/delete_account/delete_account_page.dart b/lib/features/menu/view/widgets/securty/delete_account/delete_account_page.dart index 9ab14a6..ee9b65a 100644 --- a/lib/features/menu/view/widgets/securty/delete_account/delete_account_page.dart +++ b/lib/features/menu/view/widgets/securty/delete_account/delete_account_page.dart @@ -5,11 +5,10 @@ import 'package:syncrow_app/features/auth/bloc/auth_cubit.dart'; import 'package:syncrow_app/features/menu/view/widgets/securty/bloc/security_bloc.dart'; import 'package:syncrow_app/features/menu/view/widgets/securty/bloc/security_event.dart'; import 'package:syncrow_app/features/menu/view/widgets/securty/bloc/security_state.dart'; +import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart'; - -import '../../../../../../generated/assets.dart'; -import '../../../../../../utils/resource_manager/color_manager.dart'; -import '../../../../../shared_widgets/default_scaffold.dart'; +import 'package:syncrow_app/generated/assets.dart'; +import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; class DeleteAccountPage extends StatelessWidget { const DeleteAccountPage({super.key}); @@ -30,25 +29,37 @@ class DeleteAccountPage extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.stretch, mainAxisAlignment: MainAxisAlignment.center, children: [ - InkWell( - onTap: () { - context.read().add(DeleteAccountEvent()); - }, - child: Container( - height: 50, - margin: const EdgeInsets.only(right: 20, left: 20), - decoration: const BoxDecoration( - color: ColorsManager.blueColor, - borderRadius: BorderRadius.all(Radius.circular(20))), - child: const Center( - child: Text( - 'Delete Account', - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w700, - color: ColorsManager.onPrimaryColor), - )), - ), + Column( + children: [ + Text( + 'Thank you for using Syncrow', + ), + SizedBox( + height: 10, + ), + ElevatedButton( + onPressed: () { + context.read().add(DeleteAccountEvent()); + }, + style: ElevatedButton.styleFrom( + backgroundColor: ColorsManager.blueColor, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + fixedSize: Size( + MediaQuery.sizeOf(context).width * 0.8, + 40, + ), + ), + child: Text( + 'Delete Account', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w700, + color: ColorsManager.onPrimaryColor), + ), + ) + ], ), ], ), @@ -68,15 +79,8 @@ class DeleteAccountPage extends StatelessWidget { ), ), const BodyMedium( - text: 'if you confirm to "delete account",', - fontWeight: FontWeight.w400, - fontSize: 16, - ), - const SizedBox( - height: 4, - ), - const BodyMedium( - text: 'the account will be deleted', + text: + 'if you confirm to "delete account",the account will be deleted', fontWeight: FontWeight.w400, fontSize: 16, ), diff --git a/lib/features/menu/view/widgets/securty/view/change_password_page.dart b/lib/features/menu/view/widgets/securty/view/change_password_page.dart index b8b7d1b..e09514b 100644 --- a/lib/features/menu/view/widgets/securty/view/change_password_page.dart +++ b/lib/features/menu/view/widgets/securty/view/change_password_page.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:syncrow_app/features/menu/view/widgets/securty/bloc/security_bloc.dart'; @@ -24,12 +23,11 @@ class ChangePasswordPage extends StatelessWidget { children: [ InkWell( onTap: () { - // In your parent widget or navigator Navigator.push( context, MaterialPageRoute( builder: (context) => BlocProvider( - create: (_) => SecurityBloc(), // Provide the Bloc + create: (_) => SecurityBloc(), child: const VerificationCodePage( title: 'Change Password', isDeleteAccountMode: false, diff --git a/lib/features/menu/view/widgets/securty/view/securty_view.dart b/lib/features/menu/view/widgets/securty/view/securty_view.dart index d7db084..837ea72 100644 --- a/lib/features/menu/view/widgets/securty/view/securty_view.dart +++ b/lib/features/menu/view/widgets/securty/view/securty_view.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/menu/view/widgets/securty/bloc/security_bloc.dart'; +import 'package:syncrow_app/features/menu/view/widgets/securty/bloc/security_event.dart'; import 'package:syncrow_app/features/menu/view/widgets/securty/view/change_password_page.dart'; import 'package:syncrow_app/features/menu/view/widgets/securty/view/verification_code_page.dart'; import 'package:syncrow_app/features/shared_widgets/default_container.dart'; @@ -8,8 +9,6 @@ import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; -import '../bloc/security_event.dart'; - class SecurtyView extends StatelessWidget { const SecurtyView({super.key}); @@ -28,145 +27,34 @@ class SecurtyView extends StatelessWidget { mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.start, children: [ - InkWell( + SecurityListTileWidget( + title: 'Change Password', onTap: () { Navigator.of(context).push(MaterialPageRoute( builder: (context) => const ChangePasswordPage(), )); }, - child: const Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - BodyMedium( - text: 'Change Password', - ), - Icon( - Icons.arrow_forward_ios, - color: ColorsManager.greyColor, - size: 15, - ) - ], - ), - // Container( - // margin: const EdgeInsets.symmetric(vertical: 15), - // height: 1, - // color: ColorsManager.greyColor, - // ), - ], - ), ), - // InkWell( - // onTap: () {}, - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // mainAxisSize: MainAxisSize.min, - // children: [ - // const Row( - // mainAxisAlignment: MainAxisAlignment.spaceBetween, - // children: [ - // BodyMedium( - // text: 'App Lock', - // ), - // Icon( - // Icons.arrow_forward_ios, - // color: ColorsManager.greyColor, - // size: 15, - // ) - // ], - // ), - // Container( - // margin: const EdgeInsets.symmetric(vertical: 15), - // height: 1, - // color: ColorsManager.greyColor, - // ), - // ], - // ), - // ), - // InkWell( - // onTap: () {}, - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // mainAxisSize: MainAxisSize.min, - // children: [ - // const Row( - // mainAxisAlignment: MainAxisAlignment.spaceBetween, - // children: [ - // BodyMedium( - // text: 'User Code', - // ), - // Icon( - // Icons.arrow_forward_ios, - // color: ColorsManager.greyColor, - // size: 15, - // ) - // ], - // ), - // Container( - // margin: const EdgeInsets.symmetric(vertical: 15), - // height: 1, - // color: ColorsManager.greyColor, - // ), - // ], - // ), - // ), Container( margin: const EdgeInsets.symmetric(vertical: 15), height: 1, color: ColorsManager.greyColor, ), - InkWell( + SecurityListTileWidget( + title: 'Delete Account', + fontColor: ColorsManager.red, onTap: () { Navigator.of(context).push(MaterialPageRoute( builder: (context) => BlocProvider( create: (_) => SecurityBloc()..add(StartTimerEvent()), child: VerificationCodePage( - title: 'Delete Account', + title: '', isDeleteAccountMode: true, ), ), )); }, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - BodyMedium( - text: 'Delete Account', - fontColor: ColorsManager.red, - ), - Icon( - Icons.arrow_forward_ios, - color: ColorsManager.greyColor, - size: 15, - ) - ], - ), - ], - ), ), - // InkWell( - // onTap: () {}, - // child: const Row( - // mainAxisAlignment: MainAxisAlignment.spaceBetween, - // children: [ - // BodyMedium( - // text: 'Device Update', - // ), - // Icon( - // Icons.arrow_forward_ios, - // color: ColorsManager.greyColor, - // size: 15, - // ) - // ], - // ), - // ), ], ), ), @@ -175,3 +63,42 @@ class SecurtyView extends StatelessWidget { ); } } + +class SecurityListTileWidget extends StatelessWidget { + final String title; + final void Function() onTap; + final Color? fontColor; + const SecurityListTileWidget({ + super.key, + required this.title, + required this.onTap, + this.fontColor, + }); + + @override + Widget build(BuildContext context) { + return InkWell( + onTap: onTap, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + BodyMedium( + text: title, + fontColor: fontColor, + ), + Icon( + Icons.arrow_forward_ios, + color: ColorsManager.greyColor, + size: 15, + ) + ], + ), + ], + ), + ); + } +} diff --git a/lib/services/api/authentication_api.dart b/lib/services/api/authentication_api.dart index 50db8ec..e813601 100644 --- a/lib/services/api/authentication_api.dart +++ b/lib/services/api/authentication_api.dart @@ -1,3 +1,4 @@ +import 'package:dio/dio.dart'; import 'package:syncrow_app/features/auth/model/login_with_email_model.dart'; import 'package:syncrow_app/features/auth/model/signup_model.dart'; import 'package:syncrow_app/features/auth/model/token.dart'; @@ -85,9 +86,16 @@ class AuthenticationAPI { } static Future deleteAccount() async { - await HTTPService().delete( - path: ApiEndpoints.deleteProfile, - expectedResponseModel: (p0) {}, - ); + try { + await HTTPService().delete( + path: ApiEndpoints.deleteProfile, + expectedResponseModel: (p0) {}, + ); + } on DioException catch (e) { + final errorData = e.response!.data; + String errorMessage = + errorData['error']['message'] ?? 'something went wrong'; + throw Exception(errorMessage); + } } }