Advertisement
rifki_cs29

SendOTPtoEmail

Mar 1st, 2022
1,278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 17.20 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_bloc/flutter_bloc.dart';
  3. import 'package:flutter_svg/svg.dart';
  4. import 'package:google_fonts/google_fonts.dart';
  5. import 'package:module_auth/domain/entities/register_access_email_success.dart';
  6. import 'package:module_auth/domain/entities/register_access_phone_success.dart';
  7. import 'package:module_auth/presentation/bloc/register_verification_email_bloc/register_verification_email_bloc.dart';
  8. import 'package:module_auth/presentation/bloc/register_verification_phone_bloc/register_verification_phone_bloc.dart';
  9. import 'package:module_auth/presentation/pages/register/submit_otp_page.dart';
  10. import 'package:module_core/common/state_enum.dart';
  11. import 'package:module_core/custom_widgets/custom_toast/custom_toast.dart';
  12. import 'package:module_core/utils/app_colors.dart';
  13. import 'package:module_core/utils/app_image.dart';
  14. import 'package:module_core/utils/app_string.dart';
  15.  
  16. class SendRegisterOtpPage extends StatelessWidget {
  17.   final RegisterAccessEmailSuccess? dataEmail;
  18.   final RegisterAccessPhoneSuccess? dataPhone;
  19.   const SendRegisterOtpPage(this.dataEmail, this.dataPhone);
  20.  
  21.   @override
  22.   Widget build(BuildContext context) {
  23.     final String c = dataEmail?.response.data?.c ?? '';
  24.     final String dEmail = dataEmail?.response.data?.d ?? '';
  25.     final String h = dataPhone?.response.data?.h ?? '';
  26.     final String dPhone = dataPhone?.response.data?.d ?? '';
  27.     final String? type =
  28.         dataEmail?.response.verificationMethods?[0].verificationType;
  29.     final String icon = (type == 'email')
  30.         ? (dataEmail?.response.verificationMethods?[0].icon ?? '')
  31.         : (dataPhone?.response.verificationMethods?[0].icon ?? '');
  32.  
  33.     return MultiBlocListener(
  34.         listeners: [
  35.           BlocListener<RegisterVerificationEmailBloc,
  36.               RegisterVerificationEmailState>(
  37.             listener: (context, state) {
  38.               if (state.state == RequestState.Loaded) {
  39.                 Navigator.of(context).push(MaterialPageRoute(
  40.                   builder: (context) => SubmitOtpPage(dataEmail, null),
  41.                 ));
  42.               } else if (state.state == RequestState.Error) {
  43.                 CustomToast.ShowCustomWidgetToast('${state.errorMessage}',
  44.                     context: context);
  45.               }
  46.             },
  47.             listenWhen: (previousState, currentState) =>
  48.                 currentState.state == RequestState.Loaded ||
  49.                 currentState.state == RequestState.Error,
  50.           ),
  51.           BlocListener<RegisterVerificationPhoneBloc,
  52.               RegisterVerificationPhoneState>(
  53.             listener: (context, state) {
  54.               if (state.state == RequestState.Loaded) {
  55.                 Navigator.of(context).push(MaterialPageRoute(
  56.                   builder: (context) => SubmitOtpPage(null, dataPhone),
  57.                 ));
  58.               } else if (state.state == RequestState.Error) {
  59.                 CustomToast.ShowCustomWidgetToast('${state.errorMessage}',
  60.                     context: context);
  61.               }
  62.             },
  63.             listenWhen: (previousState, currentState) =>
  64.                 currentState.state == RequestState.Loaded ||
  65.                 currentState.state == RequestState.Error,
  66.           )
  67.         ],
  68.         child: Scaffold(
  69.           backgroundColor: Colors.white,
  70.           body: BlocBuilder<RegisterVerificationEmailBloc,
  71.               RegisterVerificationEmailState>(
  72.             builder: (context, state) {
  73.               if (state.state == RequestState.Loading) {
  74.                 return Center(
  75.                     child: Container(
  76.                   height: 250,
  77.                   width: double.infinity,
  78.                   child: Image.asset(AppImage.loadingGif),
  79.                 ));
  80.               } else {
  81.                 return BlocBuilder<RegisterVerificationPhoneBloc,
  82.                     RegisterVerificationPhoneState>(
  83.                   builder: (context, state) {
  84.                     if (state.state == RequestState.Loading) {
  85.                       return Center(
  86.                           child: Container(
  87.                         height: 250,
  88.                         width: double.infinity,
  89.                         child: Image.asset(AppImage.loadingGif),
  90.                       ));
  91.                     } else {
  92.                       return SafeArea(
  93.                         child: Stack(children: [
  94.                           Positioned(
  95.                               bottom: 0,
  96.                               width: MediaQuery.of(context).size.width,
  97.                               child: Column(
  98.                                 children: [
  99.                                   Container(
  100.                                     margin: EdgeInsets.only(top: 20),
  101.                                     height: 2,
  102.                                     decoration: BoxDecoration(
  103.                                       image: DecorationImage(
  104.                                         image: AssetImage(AppImage.footer_line),
  105.                                         fit: BoxFit.cover,
  106.                                       ),
  107.                                     ),
  108.                                   ),
  109.                                   SizedBox(height: 6),
  110.                                   Text(
  111.                                     'Copyright © 2021 UKUR | All Rights Reserved',
  112.                                     textAlign: TextAlign.center,
  113.                                     style: GoogleFonts.roboto(
  114.                                         fontSize: 12,
  115.                                         fontWeight: FontWeight.w400,
  116.                                         color: Color(0xff2D2F2E)),
  117.                                   ),
  118.                                   SizedBox(height: 6),
  119.                                 ],
  120.                               )),
  121.                           ListView(
  122.                             children: [
  123.                               Stack(
  124.                                 children: [
  125.                                   Container(
  126.                                     height: 72,
  127.                                     decoration: BoxDecoration(
  128.                                       border: Border(
  129.                                         bottom: BorderSide(
  130.                                             width: 1.0,
  131.                                             color: Color(0xffC4C4C4)),
  132.                                       ),
  133.                                       color: Colors.white,
  134.                                     ),
  135.                                     child: Padding(
  136.                                       padding: const EdgeInsets.only(
  137.                                           left: 30, top: 18),
  138.                                       child: Row(
  139.                                         children: [
  140.                                           GestureDetector(
  141.                                             onTap: () => Navigator.pop(context),
  142.                                             child: Container(
  143.                                               width: 32,
  144.                                               height: 32,
  145.                                               decoration: BoxDecoration(
  146.                                                 color: AppColors.greyLight,
  147.                                                 borderRadius:
  148.                                                     BorderRadius.circular(18),
  149.                                               ),
  150.                                               child: SvgPicture.asset(
  151.                                                   AppImage.back_button,
  152.                                                   height: 24,
  153.                                                   width: 24,
  154.                                                   fit: BoxFit.scaleDown),
  155.                                             ),
  156.                                           ),
  157.                                         ],
  158.                                       ),
  159.                                     ),
  160.                                   ),
  161.                                   Center(
  162.                                     child: Padding(
  163.                                       padding: const EdgeInsets.only(top: 32),
  164.                                       child: Text(
  165.                                         'Verifikasi',
  166.                                         style: GoogleFonts.poppins(
  167.                                           fontSize: 16,
  168.                                           fontWeight: FontWeight.w600,
  169.                                           color: Color(0xff2D2F2E),
  170.                                         ),
  171.                                         textAlign: TextAlign.center,
  172.                                       ),
  173.                                     ),
  174.                                   ),
  175.                                 ],
  176.                               ),
  177.                               SizedBox(height: 24),
  178.                               Column(
  179.                                 children: [
  180.                                   Text(
  181.                                     'Metode Verifikasi',
  182.                                     style: GoogleFonts.roboto(
  183.                                       fontSize: 14,
  184.                                       fontWeight: FontWeight.w500,
  185.                                       color: Color(0xff2D2F2E),
  186.                                     ),
  187.                                   ),
  188.                                   SizedBox(height: 8),
  189.                                   Text(
  190.                                     'Anda akan mendapatkan kode',
  191.                                     textAlign: TextAlign.center,
  192.                                     style: GoogleFonts.roboto(
  193.                                       fontSize: 12,
  194.                                       fontWeight: FontWeight.w400,
  195.                                       color: Color(0xff2D2F2E),
  196.                                     ),
  197.                                   ),
  198.                                   SizedBox(height: 6),
  199.                                   Text(
  200.                                     type == 'email'
  201.                                         ? 'verifikasi melalui email.'
  202.                                         : 'verifikasi melalui SMS.',
  203.                                     textAlign: TextAlign.center,
  204.                                     style: GoogleFonts.roboto(
  205.                                       fontSize: 12,
  206.                                       fontWeight: FontWeight.w400,
  207.                                       color: Color(0xff2D2F2E),
  208.                                     ),
  209.                                   ),
  210.                                   Padding(
  211.                                     padding: const EdgeInsets.only(top: 24),
  212.                                     child: Container(
  213.                                       height: 140,
  214.                                       width: 106,
  215.                                       decoration: BoxDecoration(
  216.                                         image: DecorationImage(
  217.                                           image: AssetImage(AppImage.otp),
  218.                                           fit: BoxFit.cover,
  219.                                         ),
  220.                                       ),
  221.                                     ),
  222.                                   ),
  223.                                 ],
  224.                               ),
  225.                               Padding(
  226.                                 padding:
  227.                                     const EdgeInsets.fromLTRB(30, 24, 30, 20),
  228.                                 child: GestureDetector(
  229.                                   onTap: () {
  230.                                     (type == 'email')
  231.                                         ? BlocProvider.of<
  232.                                                     RegisterVerificationEmailBloc>(
  233.                                                 context)
  234.                                             .add(
  235.                                                 OnClickRegisterVerificationEmail(
  236.                                                     c, dEmail))
  237.                                         : BlocProvider.of<
  238.                                                     RegisterVerificationPhoneBloc>(
  239.                                                 context)
  240.                                             .add(
  241.                                                 OnClickRegisterVerificationPhone(
  242.                                                     h, dPhone));
  243.                                   },
  244.                                   child: Container(
  245.                                     padding: const EdgeInsets.symmetric(
  246.                                         vertical: 12, horizontal: 16),
  247.                                     height: 60,
  248.                                     decoration: BoxDecoration(
  249.                                         borderRadius: BorderRadius.circular(8),
  250.                                         border: Border.all(
  251.                                             color: AppColors.orangeLight)),
  252.                                     child: Column(
  253.                                       children: [
  254.                                         Row(
  255.                                           crossAxisAlignment:
  256.                                               CrossAxisAlignment.start,
  257.                                           children: [
  258.                                             Container(
  259.                                               width: 20,
  260.                                               height:
  261.                                                   (type == 'email') ? 16 : 20,
  262.                                               decoration: BoxDecoration(
  263.                                                 image: DecorationImage(
  264.                                                   image: NetworkImage(
  265.                                                       '${AppString.imageIcon}${icon}'),
  266.                                                   fit: BoxFit.cover,
  267.                                                 ),
  268.                                               ),
  269.                                             ),
  270.                                             SizedBox(width: 8),
  271.                                             Column(
  272.                                               crossAxisAlignment:
  273.                                                   CrossAxisAlignment.start,
  274.                                               children: [
  275.                                                 Text(
  276.                                                   (type == 'email')
  277.                                                       ? 'Melalui email ke'
  278.                                                       : 'Melalui SMS ke',
  279.                                                   style: GoogleFonts.roboto(
  280.                                                     fontSize: 12,
  281.                                                     fontWeight: FontWeight.w400,
  282.                                                     color: Color(0xff505050),
  283.                                                   ),
  284.                                                 ),
  285.                                                 SizedBox(height: 4),
  286.                                                 Text(
  287.                                                   (type == 'email')
  288.                                                       ? (dataEmail
  289.                                                               ?.response
  290.                                                               .verificationMethods?[
  291.                                                                   0]
  292.                                                               .text ??
  293.                                                           'email@email.com')
  294.                                                       : (dataPhone
  295.                                                               ?.response
  296.                                                               .verificationMethods?[
  297.                                                                   0]
  298.                                                               .verificationType ??
  299.                                                           '081234567890'),
  300.                                                   style: GoogleFonts.roboto(
  301.                                                     fontSize: 12,
  302.                                                     fontWeight: FontWeight.w600,
  303.                                                     color: Color(0xff505050),
  304.                                                   ),
  305.                                                 )
  306.                                               ],
  307.                                             ),
  308.                                           ],
  309.                                         ),
  310.                                       ],
  311.                                     ),
  312.                                   ),
  313.                                 ),
  314.                               )
  315.                             ],
  316.                           ),
  317.                         ]),
  318.                       );
  319.                     }
  320.                   },
  321.                 );
  322.               }
  323.             },
  324.           ),
  325.         ));
  326.   }
  327. }
  328.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement