From 59e046bd925b7d87985587357ecaa147637cff9c Mon Sep 17 00:00:00 2001 From: Dian Bayu Nugroho Date: Mon, 26 Feb 2024 13:44:27 +0700 Subject: [PATCH] fix: add validation form email --- .../view/submission_data/submit_email.dart | 162 ++++++++++-------- 1 file changed, 94 insertions(+), 68 deletions(-) diff --git a/lib/features/auth/registration/view/submission_data/submit_email.dart b/lib/features/auth/registration/view/submission_data/submit_email.dart index bf367fe..80f8ccc 100644 --- a/lib/features/auth/registration/view/submission_data/submit_email.dart +++ b/lib/features/auth/registration/view/submission_data/submit_email.dart @@ -15,41 +15,71 @@ import 'package:provider/provider.dart'; class SubmitEmail extends StatelessWidget { const SubmitEmail({Key? key}) : super(key: key); - Widget _emailVerify() { - return Column( - children: [ - const ImageView(image: PathAssets.imgEmail), - Align( - alignment: Alignment.center, - child: RichText( - textAlign: TextAlign.center, - text: TextSpan(children: [ - const TextSpan( - text: - 'We have sent a verification link to your e-mail. \nPlease check your email for ', - style: TextStyle( - color: Colors.black, - decoration: TextDecoration.none, + Widget _emailVerify(BuildContext context, SubmissionDataViewModel provider) { + var textTheme = Theme.of(context).textTheme; + return Padding( + padding: const EdgeInsets.all(24.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const TextCaption(title: 'Check your e-mail'), + const ImageView(image: PathAssets.imgEmail), + Align( + alignment: Alignment.center, + child: RichText( + textAlign: TextAlign.center, + text: TextSpan(children: [ + TextSpan( + text: + 'We have sent a verification link to your e-mail. \nPlease check your email for ', + style: textTheme.displayMedium, ), - ), - TextSpan( - recognizer: TapGestureRecognizer()..onTap = () {}, - text: 'verification', - style: const TextStyle( - color: Colors.blue, + TextSpan( + recognizer: TapGestureRecognizer() + ..onTap = () async { + await provider.next(context).then((value) { + if (value) { + routePush(context, page: const SubmissionParent()); + } + }); + }, + text: 'verification', + style: const TextStyle( + color: Colors.blue, + ), ), - ), - const TextSpan( - text: ' to \ncontinue registration.', - style: TextStyle( - color: Colors.black, - decoration: TextDecoration.none, + TextSpan( + text: ' to \ncontinue registration.', + style: textTheme.displayMedium, ), - ), - ]), + ]), + ), ), + ], + ), + ); + } + + showEmailVerify(BuildContext context, SubmissionDataViewModel provider) { + Navigator.pop(context); + showModalBottomSheet( + context: context, + isScrollControlled: true, + enableDrag: false, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.vertical( + top: Radius.zero, ), - ], + ), + builder: (context) { + var flutterView = View.of(context); + return Padding( + padding: EdgeInsets.only( + top: MediaQueryData.fromView(flutterView).padding.top, + ), + child: _emailVerify(context, provider), + ); + }, ); } @@ -60,45 +90,41 @@ class SubmitEmail extends StatelessWidget { builder: (context, child) { return Consumer( builder: (context, provider, child) { - return SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - // mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - !provider.isEmailVerify - ? const TextCaption(title: 'Enter your e-mail') - : const TextCaption(title: 'Check your e-mail '), - !provider.isEmailVerify - ? TextFormView( - name: 'E-mail Address', - hintText: 'Input e-mail address', - keyboardType: TextInputType.emailAddress, - validator: (value) { - if (value!.isEmpty) { - return 'Filled cannot be empty'; - } else if (!StringUtils.emailValidation(value)) { - return 'Format email wrong'; - } else { - return null; - } - }, - // onTap: () { - // provider.submitEmail(); - // }, - ) - : _emailVerify(), - SizedBox(height: SizeConfig.height * .42), - ButtonView( - name: 'Next', - onPressed: () async { - await provider.next(context).then((value) { - if (value) { - routePush(context, page: const SubmissionParent()); + return SizedBox( + height: SizeConfig.height * .78, + child: Form( + key: provider.formKeySubmitEmail, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + const TextCaption(title: 'Enter your e-mail'), + TextFormView( + name: 'E-mail Address', + hintText: 'Input e-mail address', + keyboardType: TextInputType.emailAddress, + validator: (value) { + if (value!.isEmpty) { + return 'Filled cannot be empty'; + } else if (!StringUtils.emailValidation(value)) { + return 'Format email wrong'; + } else { + return null; } - }); - }, - ) - ], + }, + ), + SizedBox(height: SizeConfig.height * .43), + ButtonView( + name: 'Next', + onPressed: () async { + if (provider.formKeySubmitEmail.currentState! + .validate()) { + showEmailVerify(context, provider); + } + }, + ) + ], + ), ), ); });