From 920dcdb046f7303fcaa72030982ce9c977b4d1cf Mon Sep 17 00:00:00 2001 From: Aidaiym Date: Thu, 15 Aug 2024 14:44:44 +0600 Subject: [PATCH] Change login widgets to stfull --- app/lib/config/router/app_router.dart | 2 +- .../login/presentation/view/sign_in_view.dart | 25 ++++++++++++++-- .../view/verification_code_view.dart | 30 +++++++++++++++---- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/app/lib/config/router/app_router.dart b/app/lib/config/router/app_router.dart index 91f32235..55ae7bbf 100644 --- a/app/lib/config/router/app_router.dart +++ b/app/lib/config/router/app_router.dart @@ -64,7 +64,7 @@ final class AppRouter { GoRoute( path: '/$loginWihtSoccial', name: loginWihtSoccial, - builder: (context, state) => SignInView(), + builder: (context, state) => const SignInView(), ), GoRoute( path: '/$devModeView', diff --git a/app/lib/modules/login/presentation/view/sign_in_view.dart b/app/lib/modules/login/presentation/view/sign_in_view.dart index a2048ea1..c62bbd15 100644 --- a/app/lib/modules/login/presentation/view/sign_in_view.dart +++ b/app/lib/modules/login/presentation/view/sign_in_view.dart @@ -16,11 +16,28 @@ import 'package:my_quran/l10n/l10.dart'; import 'package:my_quran/theme/theme.dart'; import 'package:my_quran/utils/urils.dart'; -class SignInView extends StatelessWidget { - SignInView({super.key}); +class SignInView extends StatefulWidget { + const SignInView({super.key}); - final emailController = TextEditingController(); + @override + State createState() => _SignInViewState(); +} + +class _SignInViewState extends State { final formKey = GlobalKey(); + late TextEditingController emailController; + + @override + void initState() { + super.initState(); + emailController = TextEditingController(); + } + + @override + void dispose() { + emailController.dispose(); + super.dispose(); + } @override Widget build(BuildContext context) { @@ -85,8 +102,10 @@ class SignInView extends StatelessWidget { AnalyticKey.goVerificationOtp, ); try { + unawaited(AppAlert.showLoading(context)); context.read().loginWithEmail(emailController.text); context.goNamed(AppRouter.verificationCode, pathParameters: {'email': emailController.text}); + if (context.mounted) context.loaderOverlay.hide(); } catch (e) { log(e.toString()); } diff --git a/app/lib/modules/login/presentation/view/verification_code_view.dart b/app/lib/modules/login/presentation/view/verification_code_view.dart index 21e971af..2b508df1 100644 --- a/app/lib/modules/login/presentation/view/verification_code_view.dart +++ b/app/lib/modules/login/presentation/view/verification_code_view.dart @@ -10,12 +10,31 @@ import 'package:my_quran/theme/custom/typography/typography_theme.dart'; import 'package:my_quran/utils/urils.dart'; import 'package:pin_code_fields/pin_code_fields.dart'; -class VerificationCodeView extends StatelessWidget { - VerificationCodeView({required this.email, super.key}); +class VerificationCodeView extends StatefulWidget { + const VerificationCodeView({required this.email, super.key}); - final TextEditingController verificationCodeController = TextEditingController(); - final GlobalKey formKey = GlobalKey(); final String email; + + @override + State createState() => _VerificationCodeViewState(); +} + +class _VerificationCodeViewState extends State { + late TextEditingController verificationCodeController; + final GlobalKey formKey = GlobalKey(); + + @override + void initState() { + super.initState(); + verificationCodeController = TextEditingController(); + } + + @override + void dispose() { + verificationCodeController.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -59,6 +78,7 @@ class VerificationCodeView extends StatelessWidget { horizontal: 50, ), child: PinCodeTextField( + autoDisposeControllers: false, key: const Key(MqKeys.otpTextField), appContext: context, length: 4, @@ -90,7 +110,7 @@ class VerificationCodeView extends StatelessWidget { AnalyticKey.tapLogin, params: {'soccial': 'email'}, ); - context.read().verifyOtp(verificationCodeController.text, email); + context.read().verifyOtp(verificationCodeController.text, widget.email); } }, text: 'Verify',