Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:async';
- import 'package:flutter/gestures.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_bloc/flutter_bloc.dart';
- import 'package:google_fonts/google_fonts.dart';
- import 'package:module_auth/domain/entities/register_access_email_success.dart';
- import 'package:module_auth/domain/entities/register_access_phone_success.dart';
- import 'package:module_auth/presentation/bloc/register_verification_email_bloc/register_verification_email_bloc.dart';
- import 'package:module_auth/presentation/bloc/register_verification_phone_bloc/register_verification_phone_bloc.dart';
- import 'package:module_core/utils/app_colors.dart';
- class RegisterResendOtp extends StatefulWidget {
- final RegisterAccessEmailSuccess? dataEmail;
- final RegisterAccessPhoneSuccess? dataPhone;
- const RegisterResendOtp(this.dataEmail, this.dataPhone);
- @override
- _RegisterResendOtpState createState() => _RegisterResendOtpState();
- }
- class _RegisterResendOtpState extends State<RegisterResendOtp> {
- late Timer _timer;
- int _second = 30;
- void startTimer() {
- const oneSec = const Duration(seconds: 1);
- _timer = new Timer.periodic(
- oneSec,
- (Timer timer) {
- if (_second == 0) {
- setState(() {
- timer.cancel();
- });
- } else {
- setState(() {
- _second--;
- });
- }
- },
- );
- }
- @override
- void initState() {
- startTimer();
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- final String c = widget.dataEmail?.response.data?.c ?? '';
- final String dEmail = widget.dataEmail?.response.data?.d ?? '';
- final String h = widget.dataPhone?.response.data?.h ?? '';
- final String dPhone = widget.dataPhone?.response.data?.d ?? '';
- final String? type =
- widget.dataEmail?.response.verificationMethods?[0].verificationType;
- return Padding(
- padding: const EdgeInsets.only(top: 18),
- child: (_second != 0)
- ? RichText(
- textAlign: TextAlign.center,
- text: TextSpan(
- text: 'Mohon tunggu dalam ${_second} detik untuk ',
- style: GoogleFonts.roboto(
- fontSize: 12,
- fontWeight: FontWeight.w400,
- color: Color(0xff2D2F2E),
- ),
- children: <TextSpan>[
- TextSpan(
- text: 'Kirim Ulang',
- style: GoogleFonts.roboto(
- fontSize: 12,
- fontWeight: FontWeight.w400,
- color: Color(0xff2D2F2E),
- )),
- ],
- ),
- )
- : RichText(
- textAlign: TextAlign.center,
- text: TextSpan(
- text: 'Tidak Menerima kode? ',
- style: GoogleFonts.roboto(
- fontSize: 12,
- fontWeight: FontWeight.w400,
- color: Color(0xff2D2F2E),
- ),
- children: <TextSpan>[
- TextSpan(
- recognizer: TapGestureRecognizer()
- ..onTap = () {
- _second = 30;
- startTimer();
- (type == 'email')
- ? context
- .read<RegisterVerificationEmailBloc>()
- .add(
- OnClickRegisterVerificationEmail(c, dEmail),
- )
- : context
- .read<RegisterVerificationPhoneBloc>()
- .add(
- OnClickRegisterVerificationPhone(h, dPhone),
- );
- },
- text: 'Kirim Ulang',
- style: GoogleFonts.roboto(
- fontSize: 12,
- fontWeight: FontWeight.w500,
- color: AppColors.grueLight,
- )),
- ],
- ),
- ),
- );
- }
- @override
- void dispose() {
- _timer.cancel();
- super.dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement