DEV Community



rrtutors profile image rrtutors Originally published at ・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

  decoration: UnderlineDecoration(
    textStyle: TextStyle(fontSize: 20, color:,
    colorBuilder: FixedColorBuilder(,
 codeLength: 4,
  onCodeSubmitted: (code) {},
  onCodeChanged: (code) {
    if (code.length == 6) {
Enter fullscreen mode Exit fullscreen mode

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

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

Alt Text

Read and run the complete Example code

Discussion (0)

Editor guide