AUTO READ SMS | FLUTTER

AUTO READ SMS | FLUTTER

Written by mouli150388 on Feb 9th, 2021 Views Report Post

Hello Guys, in this post we will cover how to read SMS OTP automatically. In Every mobile application there is mobile number verification feature will be available. To Verify the Mobile Numbers by sending the SMS OTP to registered mobile numbers.

When user receives the OTP he has to copy and paste the code will get irritate by users. To avoid this apps will try to read received SMS OTP and fill the TestFields automatically. To do auto read SMS OTP we have a library plugin called sms_autofill



The AUTO Fill widget will be used to read the SMS
PinFieldAutoFill(
  decoration: UnderlineDecoration(
    textStyle: TextStyle(fontSize: 20, color: Colors.black),
    colorBuilder: FixedColorBuilder(Colors.black.withOpacity(0.3)),
  ),
 codeLength: 4,
  onCodeSubmitted: (code) {},
  onCodeChanged: (code) {
    if (code.length == 6) {
      FocusScope.of(context).requestFocus(FocusNode());
    }
  },
)

Listen OTP Events To listen the SMS events we need to call SMS Listener on initState() method


```java _listOPT() async { await SmsAutoFill().listenForCode; } ```

SMS FORMAT The SMS should be the below format

<#> SampleApp: Your verification code is 1435
Z66b5+ou+DI

auto-sms-otp.jpg

Read and run the complete Example code

Comments (0)