搜索插件、代码仓与 APP 分类

sms_autofill 封面
插件详情v2.6.1

sms_autofill

Flutter 插件,用于提供短信验证码自动填充支持

AndroidiOS
近 30 天下载
20.7万
喜欢数
881
Pub 分数
140

安装插件

flutter pub add sms_autofill

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

sms_autofill 包是一个 Flutter 插件,可在 Android 和 iOS 上实现短信验证码的自动检测和自动填充。它通过自动提取通过短信发送的一次性密码(OTP),简化了认证流程中的用户体验,减少手动输入错误并提高转化率。该插件可与专为 OTP 输入设计的文本字段无缝集成,利用平台特定的 API 检测传入的消息,并自动填充字段。

适合场景

  • 登录流程中的自动OTP输入
  • 减少账户验证中的用户摩擦
  • 提高表单完成率
  • 支持双因素认证
  • 启用短信验证码快速注册

主要特点

  • 自动短信验证码检测
  • 跨平台支持(Android 和 iOS)
  • 与 TextFormField 的无缝集成
  • 所需设置最少
  • 从传入消息中实时提取代码

适合对象

  • 需要输入OTP的身份验证屏幕
  • 使用短信双因素认证的应用
  • 带有电话验证的用户入门流程
  • 寻求改进PIN/OTP字段用户体验的开发者
  • 旨在减少表单放弃的项目

使用建议

  • 需要正确的短信消息格式以进行检测
  • 可能不适用于所有设备或运营商
  • 对哪些消息会自动填充的控制有限
  • 依赖于平台级短信权限
  • 不能保证在所有模拟器环境中都能正常工作

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

sms_autofill

pub package Flutter plugin to provide SMS code autofill support.

For iOS, this package is not needed as the SMS autofill is provided by default, but not for Android, that's where this package is useful.

No permission to read SMS messages is asked to the user as there no need thanks to SMSRetriever API.

Usage

You have two widgets at your disposable for autofill an SMS code, PinFieldAutoFill and TextFieldPinAutoFill.

Just before you sent your phone number to the backend, you need to let the plugin know that it needs to listen for the SMS with the code.

To do that you need to do:

await SmsAutoFill().listenForCode();

This will listen for the SMS with the code during 5 minutes and when received, autofill the following widget.

PinFieldAutoFill

PinFieldAutoFill

PinFieldAutoFill(
                decoration: // UnderlineDecoration, BoxLooseDecoration or BoxTightDecoration see https://github.com/TinoGuo/pin_input_text_field for more info,
                currentCode: // prefill with a code
                onCodeSubmitted: //code submitted callback
                onCodeChanged: //code changed callback
                codeLength: //code length, default 6
              ),
TextFieldPinAutoFill

TextFieldPinAutoFill

TextFieldPinAutoFill(
                decoration: // basic InputDecoration
                currentCode: // prefill with a code
                onCodeSubmitted: //code submitted callback
                onCodeChanged: //code changed callback
                codeLength: //code length, default 6
              ),
Android SMS constraint

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

  • Be no longer than 140 bytes
  • Contain a one-time code that the client sends back to your server to complete the verification flow
  • End with an 11-character hash string that identifies your app

One example of SMS would be:

ExampleApp: Your code is 123456
FA+9qCX9VSu

Helper

PhoneFieldHint [Android only]

PhoneFieldHint is a widget that will allow you ask for system phone number and autofill the widget if a phone is choosen by the user.

Phone hint

Custom CodeAutoFill

If you want to create a custom widget that will autofill with the sms code, you can use the CodeAutoFill mixin that will offer you:

  • listenForCode() to listen for the SMS code from the native plugin when SMS is received, need to be called on your initState.
  • cancel() to dispose the subscription of the SMS code from the native plugin, need to be called on your dispose.
  • codeUpdated() called when the code is received, you can access the value with the field code.
  • unregisterListener() to unregister the broadcast receiver, need to be called on your dispose.
App Signature

To get the app signature at runtime just call the getter getAppSignature on SmsAutoFill. You can also find the sample code in example app.

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目