OTP verification in Flutter

Ankit dwivedi
2 min readDec 5, 2022

--

In this blog we are trying to achieve Flutter auto read SMS or OTP with SMS Retriever API. This api help us to read SMS content automatically in our app.

With this API, SMS content will be automatically read by our app.

To implement a full SMS verification flow using the SMS User Consent API you need to interact with both a backend server to send the SMS as well as the SMS User Consent API to prompt the user for access to a single message containing a one-time code.

Step by step guide to implement SMS verification :-

First app should calls the SMS User Consent API to start listening for an SMS response from the server side. An SMS received previously, to start SMS User Consent, will not be forwarded to the app.

After starting the SMS User Consent API, app will make a request to a server for user’s phone verification via OTP.

When user receives OTP, Google Play services displays the message to the user and asks for his/her consent, to make that text available inside the app.

If user consents, then SMS will be available for the app. Then we will parses OTP from the message text and send back to the server for verification.

When a user tries to log in to app, we tries to pick up user phone number and send it to the server, so that server can send an OTP to that mobile number.

Their are various ways in which we can get users phone number such as giving him option to enter his number or allow Google Auth Api to get the mobile number from associated google account. For that we need some dependency to add in our build.gradle (app level).

Android dependency in app/build.gradle

Add Dependency to your pubspec.yaml

Showing Sms User consent

Source: https://developers.google.com/identity/sms-retriever/user-consent/overview

That’s it for all guys, you successfully verify user’s phone number.

Thanks for reading, Happy coding :)

Keep learning and keep sharing. Thank you.

--

--

Ankit dwivedi
Ankit dwivedi

Written by Ankit dwivedi

Software developer ? ( Flutter || Dart || IOS ||C# || Nodejs || Kotlin || Java || Android ) : Writing

No responses yet