gpt4 book ai didi

flutter - 如何从 SMS 获取 OTP - 自动填充

转载 作者:行者123 更新时间:2023-12-04 01:08:28 31 4
gpt4 key购买 nike

我想自动捕获或读取 SMS 消息的 OTP。我做了一些像这样的代码测试:

import 'package:flutter/material.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Demo Auto OTP'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);

final String title;

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
TextEditingController _textController = TextEditingController();
String _error;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Multi-Factor-Authentication"),
),
body: Form(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: _textController,
autofillHints: [ AutofillHints.oneTimeCode ],
keyboardType: TextInputType.visiblePassword,
maxLength: 6,
maxLengthEnforced: true,
style: TextStyle(fontSize: 32),
),

RaisedButton(
child: Text("Verify"),
onPressed: () => Navigator.of(context).pop(_textController.value.text),
),
],
),
)
);
}
}
这是测试短信: 12345 is your code to log in.oneTimeCode 的 flutter 文档:
https://api.flutter.dev/flutter/services/AutofillHints/oneTimeCode-constant.html
flutter 自动填充: https://github.com/flutter/flutter/blob/7891006299/packages/flutter/lib/src/services/autofill.dart#L362
IOS: https://developer.apple.com/documentation/uikit/uitextcontenttype
安卓 :
https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_SMS_OTP

最佳答案

你可以使用这个包:https://pub.dev/packages/sms_autofill
但请考虑以下限制:

Android SMS constraint For the code to be receive, it need to followsome rules as describe here:https://developers.google.com/identity/sms-retriever/verify

Be no longer than 140 bytes Begin with the prefix <#> Contain aone-time code that the client sends back to your server to completethe verification flow End with an 11-character hash string thatidentifies your app One example of SMS would be:

<#> ExampleApp: Your code is 123456 FA+9qCX9VSu

关于flutter - 如何从 SMS 获取 OTP - 自动填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65559187/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com