@ -1,15 +1,15 @@
import ' dart:async ' ;
import ' package:easy_localization/ src/public_ext .dart' ;
import ' package:easy_localization/ easy_localization .dart' ;
import ' package:flutter/material.dart ' ;
import ' package:flutter_svg/svg.dart ' ;
import ' package:hmg_nurses/classes/colors.dart ' ;
import ' package:hmg_nurses/extensions/int_extensions.dart ' ;
import ' package:hmg_nurses/extensions/string_extensions.dart ' ;
import ' package:hmg_nurses/generated/locale_keys.g.dart ' ;
import ' package:hmg_nurses/widgets/button/default_button.dart ' ;
import ' package:hmg_nurses/widgets/otp_widget.dart ' ;
final ValueNotifier < String > otpFieldClear = ValueNotifier < String > ( " " ) ;
class OtpDialog {
@ -17,18 +17,13 @@ class OtpDialog {
final int ? mobileNo ;
final Function ( String , TextEditingController _pinPutController ) onSuccess ;
final Function onFailure ;
final BuildContext context ;
final Function onResendCode ;
int remainingTime = 120 ;
Future < Null > ? timer ;
static BuildContext ? _context ;
static bool ? _loading ;
OtpDialog ( this . context , this . type , this . mobileNo , this . onSuccess , this . onFailure , { required this . onResendCode } ) ;
OtpDialog ( { required this . type , required this . mobileNo , required this . onSuccess , required this . onFailure , required this . onResendCode } ) ;
GlobalKey ? verifyAccountForm = GlobalKey < FormState > ( ) ;
@ -53,7 +48,6 @@ class OtpDialog {
/ / ProjectViewModel projectProvider ;
String displayTime = ' ' ;
String ? _code ;
dynamic setState ;
bool stopTimer = false ;
@ -75,7 +69,7 @@ class OtpDialog {
}
return Container (
padding: EdgeInsets . all ( 21 ) ,
padding: const EdgeInsets . all ( 21 ) ,
child: Column (
mainAxisSize: MainAxisSize . min ,
crossAxisAlignment: CrossAxisAlignment . start ,
@ -92,38 +86,33 @@ class OtpDialog {
width: 50 ,
) ,
12. height ,
" LocaleKeys.otp.tr() " . toText14 ( ) ,
" LocaleKeys.verification.tr() " . toText24 ( isBold: true ) ,
LocaleKeys . otp . tr ( ) . toText14 ( ) ,
LocaleKeys . verification . tr ( ) . toText24 ( isBold: true ) ,
6. height ,
( " LocaleKeys.pleaseEnterTheVerificationCodeSentTo.tr() " + ' xxxxxxxx ' + mobileNo . toString ( ) . substring ( mobileNo . toString ( ) . length - 3 ) ) . toText16 ( ) ,
( ' ${ LocaleKeys . pleaseEnterTheVerificationCodeSentTo . tr ( ) } xxxxxxxx ${ mobileNo . toString ( ) . substring ( mobileNo . toString ( ) . length - 3 ) } ' ) . toText16 ( ) ,
18. height ,
ValueListenableBuilder < String > (
builder: ( BuildContext context , String value , Widget ? child ) {
/ / This builder will only get called when the _counter
/ / is updated .
return Column (
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
Directionality (
textDirection: TextDirection . ltr ,
child: Center (
child: OTPWidget (
autoFocus: true ,
controller: _pinPutController ,
defaultBorderColor: const Color ( 0xffD8D8D8 ) ,
maxLength: 4 ,
onTextChanged: ( text ) { } ,
pinBoxColor: Colors . white ,
onDone: ( code ) = > _onOtpCallBack ( code , null ) ,
textBorderColor: const Color ( 0xffD8D8D8 ) ,
pinBoxWidth: 60 ,
pinBoxHeight: 60 ,
pinTextStyle: const TextStyle ( fontSize: 24.0 , color: MyColors . darkTextColor ) ,
pinTextAnimatedSwitcherTransition: ProvidedPinBoxTextAnimation . scalingTransition ,
pinTextAnimatedSwitcherDuration: const Duration ( milliseconds: 300 ) ,
pinBoxRadius: 10 ,
keyboardType: TextInputType . number ,
) ,
Center (
child: OTPWidget (
autoFocus: true ,
controller: _pinPutController ,
defaultBorderColor: const Color ( 0xffD8D8D8 ) ,
maxLength: 4 ,
onTextChanged: ( text ) { } ,
pinBoxColor: Colors . white ,
onDone: ( code ) = > _onOtpCallBack ( code , null ) ,
textBorderColor: const Color ( 0xffD8D8D8 ) ,
pinBoxWidth: 60 ,
pinBoxHeight: 60 ,
pinTextStyle: const TextStyle ( fontSize: 24.0 , color: MyColors . darkTextColor ) ,
pinTextAnimatedSwitcherTransition: ProvidedPinBoxTextAnimation . scalingTransition ,
pinTextAnimatedSwitcherDuration: const Duration ( milliseconds: 300 ) ,
pinBoxRadius: 10 ,
keyboardType: TextInputType . number ,
) ,
) ,
10. height ,
@ -131,7 +120,7 @@ class OtpDialog {
? Row (
children: [
Expanded (
child: " LocaleKeys.codeExpire.tr() " . toText16 (
child: LocaleKeys . codeExpire . tr ( ) . toText16 (
color: MyColors . redColor ,
) ,
) ,
@ -146,7 +135,7 @@ class OtpDialog {
)
: RichText (
text: TextSpan (
text: " LocaleKeys.theVerificationCodeWillExpireIn.tr() " + ' \n ' ,
text: ' ${ LocaleKeys . theVerificationCodeWillExpireIn . tr ( ) } \n ' ,
style: const TextStyle ( fontSize: 16 , fontWeight: FontWeight . w600 , color: MyColors . darkTextColor , letterSpacing: - 0.48 ) ,
children: < TextSpan > [
TextSpan (
@ -163,7 +152,7 @@ class OtpDialog {
) ,
18. height ,
DefaultButton (
stopTimer ? " LocaleKeys.resend.tr() " : " LocaleKeys.cancel.tr() " ,
stopTimer ? LocaleKeys . resend . tr ( ) : LocaleKeys . cancel . tr ( ) ,
( ) async {
if ( stopTimer ) {
hideSMSBox ( context ) ;
@ -177,8 +166,8 @@ class OtpDialog {
colors: stopTimer
? null
: [
MyColors . pinkDark Color,
MyColors . pinkDark Color,
MyColors . red Color,
MyColors . red Color,
] ,
) ,
] ,
@ -211,16 +200,6 @@ class OtpDialog {
) ;
}
/ / String validateCodeDigit ( value ) {
/ / if ( value . isEmpty ) {
/ / return ' ' ;
/ / } else if ( value . length = = 3 ) {
/ / print ( value ) ;
/ / } else {
/ / return null ;
/ / }
/ / }
String getSecondsAsDigitalClock ( int inputSeconds ) {
int secNum = int . parse ( inputSeconds . toString ( ) ) ; / / don ' t forget the second param
int hours = ( secNum / 3600 ) . floor ( ) ;
@ -228,9 +207,9 @@ class OtpDialog {
double seconds = secNum - hours * 3600 - minutes * 60 ;
String minutesString = " " ;
String secondsString = " " ;
minutesString = minutes < 10 ? " 0 " + minutes . toString ( ) : minutes . toString ( ) ;
secondsString = seconds < 10 ? " 0 " + seconds . toStringAsFixed ( 0 ) : seconds . toStringAsFixed ( 0 ) ;
return minutesString + " : " + secondsString ;
minutesString = minutes < 10 ? " 0 $ minutes " : minutes . toString ( ) ;
secondsString = seconds < 10 ? " 0 ${ seconds . toStringAsFixed ( 0 ) } " : seconds . toStringAsFixed ( 0 ) ;
return " $ minutesString : $ secondsString " ;
}
void startTimer ( setState ) {