DEV Community

loading...

AUTO READ SMS | FLUTTER

rrtutors profile image rrtutors Originally published at rrtutors.com ・1 min read

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());
    }
  },
)
Enter fullscreen mode Exit fullscreen mode

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

_listOPT()
async {
  await SmsAutoFill().listenForCode;
}
Enter fullscreen mode Exit fullscreen mode

Alt Text



Read and run the complete Example code

Discussion (0)

pic
Editor guide