搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案