Flutter 颤振sms#U自动填充不';我不总是自动读取OTP 导入“包装:颤振/材料.省道”; 导入“包:sms_autofill/sms_autofill.dart”; 导入“../../widgets/color_loader.dart”; 导入“../../models/login_api_response_model.dart”; 导入“//../services/Authentication/Authentication_service.dart”; 导入“../../models/enum_models.dart”; 导入“./login\u error\u page.dart”; 类ValidateOp扩展StatefulWidget{ 最终字符串移动枚举器; ValidateOtp({@required this.mobileNumber}); @凌驾 _ValidateOtpState createState()=>\u ValidateOtpState(); } 类_ValidateOtpState扩展状态{ 最终SmsAutoFill _自动填充=SmsAutoFill(); bool=failed=false; 未来的反应; LoginApiResponseModel LoginApiResponseModel; bool-isInit=true; bool resendOtp=false; 字符串otp; void fetchOtp(){ 打印(“设置状态获取OTP”); response=AuthenticationService.generateOtp(widget.mobileNumber) .然后((值)=>loginApiResponseModel=value); } @凌驾 void initState(){ _listenOTP(); fetchOtp(); super.initState(); } void\u listenOTP()异步{ 等待SmsAutoFill().listenForCode; } validateOtp(字符串otp){ 打印(“收到代码$otp”); } @凌驾 无效处置(){ SmsAutoFill().取消注册侦听器(); super.dispose(); } @凌驾 小部件构建(构建上下文){ 打印(“${u autoFill.getAppSignature}”); 返回脚手架( 正文:未来建设者( 未来:回应, 生成器:(上下文,dataSnapShopt){ if(dataSnapShopt.connectionState==connectionState.waiting){ 返回中心( 子项:ColorLoader(), ); }else if(dataSnapShopt.error!=null){ 返回中心( 孩子:文本(‘出了点问题……), ); }否则{ return loginApiResponseModel.status==“失败” ?登录者页面( errorMessage:'无效的手机号码!', errorType:errorType.InvalidMobileEnumber, ) :列( mainAxisAlignment:mainAxisAlignment.center, 儿童:[ 容器( 孩子:填充( 填充:常数边集全部(10.0), 子项:Pinfield自动填充( 自动对焦:对, 键盘类型:TextInputType.number, 代码长度:6, onCodeChanged:(值){ 如果(value.length==6){ 打印('onCodeChanged'); otp=价值; } }, ), ), ), 容器( 子级:FloatingActionButton.extended( 按下:()=>validateOtp(otp), 标签:文本(“确认”), ), ), 划船( mainAxisAlignment:mainAxisAlignment.center, 儿童:[ 文本('没有收到OTP?'), 扁平按钮( 已按下:(){ 设置状态(){ resendOtp=!resendOtp; }); fetchOtp(); }, 子项:文本(“重新发送”), ) ], ) ], ); } }, ), ); } }
嗨, 我正在使用sms_autofill 1.2.3自动填写OTP。 我的flatter应用程序能够自动读取OTP,但并不总是这样,比如当我进行一些更改并进行热重新加载时,或者甚至在再次运行flatter run之后,有时它无法读取代码。我是否遗漏了什么? 我正在使用sms_autofill 1.2.3自动填写OTP。Flutter 颤振sms#U自动填充不';我不总是自动读取OTP 导入“包装:颤振/材料.省道”; 导入“包:sms_autofill/sms_autofill.dart”; 导入“../../widgets/color_loader.dart”; 导入“../../models/login_api_response_model.dart”; 导入“//../services/Authentication/Authentication_service.dart”; 导入“../../models/enum_models.dart”; 导入“./login\u error\u page.dart”; 类ValidateOp扩展StatefulWidget{ 最终字符串移动枚举器; ValidateOtp({@required this.mobileNumber}); @凌驾 _ValidateOtpState createState()=>\u ValidateOtpState(); } 类_ValidateOtpState扩展状态{ 最终SmsAutoFill _自动填充=SmsAutoFill(); bool=failed=false; 未来的反应; LoginApiResponseModel LoginApiResponseModel; bool-isInit=true; bool resendOtp=false; 字符串otp; void fetchOtp(){ 打印(“设置状态获取OTP”); response=AuthenticationService.generateOtp(widget.mobileNumber) .然后((值)=>loginApiResponseModel=value); } @凌驾 void initState(){ _listenOTP(); fetchOtp(); super.initState(); } void\u listenOTP()异步{ 等待SmsAutoFill().listenForCode; } validateOtp(字符串otp){ 打印(“收到代码$otp”); } @凌驾 无效处置(){ SmsAutoFill().取消注册侦听器(); super.dispose(); } @凌驾 小部件构建(构建上下文){ 打印(“${u autoFill.getAppSignature}”); 返回脚手架( 正文:未来建设者( 未来:回应, 生成器:(上下文,dataSnapShopt){ if(dataSnapShopt.connectionState==connectionState.waiting){ 返回中心( 子项:ColorLoader(), ); }else if(dataSnapShopt.error!=null){ 返回中心( 孩子:文本(‘出了点问题……), ); }否则{ return loginApiResponseModel.status==“失败” ?登录者页面( errorMessage:'无效的手机号码!', errorType:errorType.InvalidMobileEnumber, ) :列( mainAxisAlignment:mainAxisAlignment.center, 儿童:[ 容器( 孩子:填充( 填充:常数边集全部(10.0), 子项:Pinfield自动填充( 自动对焦:对, 键盘类型:TextInputType.number, 代码长度:6, onCodeChanged:(值){ 如果(value.length==6){ 打印('onCodeChanged'); otp=价值; } }, ), ), ), 容器( 子级:FloatingActionButton.extended( 按下:()=>validateOtp(otp), 标签:文本(“确认”), ), ), 划船( mainAxisAlignment:mainAxisAlignment.center, 儿童:[ 文本('没有收到OTP?'), 扁平按钮( 已按下:(){ 设置状态(){ resendOtp=!resendOtp; }); fetchOtp(); }, 子项:文本(“重新发送”), ) ], ) ], ); } }, ), ); } },flutter,autofill,Flutter,Autofill,嗨, 我正在使用sms_autofill 1.2.3自动填写OTP。 我的flatter应用程序能够自动读取OTP,但并不总是这样,比如当我进行一些更改并进行热重新加载时,或者甚至在再次运行flatter run之后,有时它无法读取代码。我是否遗漏了什么? 我正在使用sms_autofill 1.2.3自动填写OTP。 我的Flatter应用程序能够自动读取OTP,但并不总是这样,比如当我进行一些更改并进行热加载时,或者甚至在再次运行Flatter run后,有时它也无法读取代码。我是否遗漏了一
我的Flatter应用程序能够自动读取OTP,但并不总是这样,比如当我进行一些更改并进行热加载时,或者甚至在再次运行Flatter run后,有时它也无法读取代码。我是否遗漏了一些内容?我可以获得您如何使用http实现sms_autofill的代码吗?@Niroop,代码随附说明。你还需要什么吗?我的错!我刚才犯了一些错误,请您告诉我们您的错误,因为我也收到了这个问题。我可以得到您如何使用http实现sms_自动填充的代码吗?@Niroop,代码随附说明。你还需要什么吗?我的错!我刚才犯了一些错误,你能告诉我们你的错误吗?因为我也遇到了这个问题
import 'package:flutter/material.dart';
import 'package:sms_autofill/sms_autofill.dart';
import './../../widgets/color_loader.dart';
import './../../models/login_api_response_model.dart';
import './../../services/Authentication/authentication_service.dart';
import './../../models/enum_models.dart';
import './login_error_page.dart';
class ValidateOtp extends StatefulWidget {
final String mobileNumber;
ValidateOtp({@required this.mobileNumber});
@override
_ValidateOtpState createState() => _ValidateOtpState();
}
class _ValidateOtpState extends State<ValidateOtp> {
final SmsAutoFill _autoFill = SmsAutoFill();
bool verifactionFailed = false;
Future<LoginApiResponseModel> response;
LoginApiResponseModel loginApiResponseModel;
bool isInit = true;
bool resendOtp = false;
String otp;
void fetchOtp() {
print('setState fetchOtp');
response = AuthenticationService.generateOtp(widget.mobileNumber)
.then((value) => loginApiResponseModel = value);
}
@override
void initState() {
_listenOTP();
fetchOtp();
super.initState();
}
void _listenOTP() async {
await SmsAutoFill().listenForCode;
}
validateOtp(String otp) {
print('Code received $otp');
}
@override
void dispose() {
SmsAutoFill().unregisterListener();
super.dispose();
}
@override
Widget build(BuildContext context) {
print('${_autoFill.getAppSignature}');
return Scaffold(
body: FutureBuilder(
future: response,
builder: (context, dataSnapShopt) {
if (dataSnapShopt.connectionState == ConnectionState.waiting) {
return Center(
child: ColorLoader(),
);
} else if (dataSnapShopt.error != null) {
return Center(
child: Text('Something went wrong..'),
);
} else {
return loginApiResponseModel.status == 'fail'
? LoginErrorPage(
errorMessage: 'Invalid Mobile number!',
errorType: ErrorType.InvalidMobileNumber,
)
: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: PinFieldAutoFill(
autofocus: true,
keyboardType: TextInputType.number,
codeLength: 6,
onCodeChanged: (value) {
if (value.length == 6) {
print(' onCodeChanged');
otp = value;
}
},
),
),
),
Container(
child: FloatingActionButton.extended(
onPressed: () => validateOtp(otp),
label: Text('Confirm'),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Didn\'t receive OTP? '),
FlatButton(
onPressed: () {
setState(() {
resendOtp = !resendOtp;
});
fetchOtp();
},
child: Text('RESEND'),
)
],
)
],
);
}
},
),
);
}
}