|
|
|
|
@ -1,11 +1,12 @@
|
|
|
|
|
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';
|
|
|
|
|
|
|
|
|
|
@ -16,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>();
|
|
|
|
|
|
|
|
|
|
@ -52,7 +48,6 @@ class OtpDialog {
|
|
|
|
|
|
|
|
|
|
// ProjectViewModel projectProvider;
|
|
|
|
|
String displayTime = '';
|
|
|
|
|
String? _code;
|
|
|
|
|
dynamic setState;
|
|
|
|
|
bool stopTimer = false;
|
|
|
|
|
|
|
|
|
|
@ -74,7 +69,7 @@ class OtpDialog {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
|
padding: EdgeInsets.all(21),
|
|
|
|
|
padding: const EdgeInsets.all(21),
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
@ -83,78 +78,73 @@ class OtpDialog {
|
|
|
|
|
type == 1
|
|
|
|
|
? "assets/images/login/verify_sms.svg"
|
|
|
|
|
: type == 2
|
|
|
|
|
? "assets/images/login/verify_whatsapp.svg"
|
|
|
|
|
: type == 3
|
|
|
|
|
? "assets/images/login/verify_face.svg"
|
|
|
|
|
: 'assets/images/login/verify_thumb.svg',
|
|
|
|
|
? "assets/images/login/verify_whatsapp.svg"
|
|
|
|
|
: type == 3
|
|
|
|
|
? "assets/images/login/verify_face.svg"
|
|
|
|
|
: 'assets/images/login/verify_thumb.svg',
|
|
|
|
|
height: 50,
|
|
|
|
|
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,
|
|
|
|
|
stopTimer
|
|
|
|
|
? Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: "LocaleKeys.codeExpire.tr()".toText16(
|
|
|
|
|
color: MyColors.redColor,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
12.width,
|
|
|
|
|
Image.asset(
|
|
|
|
|
"assets/icons/ic_alarm.png",
|
|
|
|
|
width: 20,
|
|
|
|
|
height: 20,
|
|
|
|
|
color: MyColors.redColor,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: LocaleKeys.codeExpire.tr().toText16(
|
|
|
|
|
color: MyColors.redColor,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
12.width,
|
|
|
|
|
Image.asset(
|
|
|
|
|
"assets/icons/ic_alarm.png",
|
|
|
|
|
width: 20,
|
|
|
|
|
height: 20,
|
|
|
|
|
color: MyColors.redColor,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
: RichText(
|
|
|
|
|
text: TextSpan(
|
|
|
|
|
text: "LocaleKeys.theVerificationCodeWillExpireIn.tr()" + '\n',
|
|
|
|
|
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: MyColors.darkTextColor, letterSpacing: -0.48),
|
|
|
|
|
children: <TextSpan>[
|
|
|
|
|
TextSpan(
|
|
|
|
|
text: displayTime,
|
|
|
|
|
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: MyColors.textMixColor, letterSpacing: -0.48),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
text: TextSpan(
|
|
|
|
|
text: '${LocaleKeys.theVerificationCodeWillExpireIn.tr()}\n',
|
|
|
|
|
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: MyColors.darkTextColor, letterSpacing: -0.48),
|
|
|
|
|
children: <TextSpan>[
|
|
|
|
|
TextSpan(
|
|
|
|
|
text: displayTime,
|
|
|
|
|
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: MyColors.textMixColor, letterSpacing: -0.48),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
@ -162,8 +152,8 @@ class OtpDialog {
|
|
|
|
|
),
|
|
|
|
|
18.height,
|
|
|
|
|
DefaultButton(
|
|
|
|
|
stopTimer ? "LocaleKeys.resend.tr()" : "LocaleKeys.cancel.tr()",
|
|
|
|
|
() async {
|
|
|
|
|
stopTimer ? LocaleKeys.resend.tr() : LocaleKeys.cancel.tr(),
|
|
|
|
|
() async {
|
|
|
|
|
if (stopTimer) {
|
|
|
|
|
hideSMSBox(context);
|
|
|
|
|
onResendCode();
|
|
|
|
|
@ -176,9 +166,9 @@ class OtpDialog {
|
|
|
|
|
colors: stopTimer
|
|
|
|
|
? null
|
|
|
|
|
: [
|
|
|
|
|
MyColors.pinkDarkColor,
|
|
|
|
|
MyColors.pinkDarkColor,
|
|
|
|
|
],
|
|
|
|
|
MyColors.redColor,
|
|
|
|
|
MyColors.redColor,
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
@ -210,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();
|
|
|
|
|
@ -227,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) {
|
|
|
|
|
@ -269,4 +249,4 @@ class OtpDialog {
|
|
|
|
|
// // return null;
|
|
|
|
|
// // }
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
}
|