Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read OTP from SMS flutter

I know about the package flutter_sms which is used for reading, writing and sending SMS.

But as I can see it will ask from user SEND_SMS permission also which is not needed and also google doesn't allow asking for this permission if your app does not solely depend on this feature.

Can anyone help me with Reading OTP from SMS with flutter?

Or can help with writing the functionality natively for both IOS and Android and integrating it with flutter.

like image 618
CodeGeek Avatar asked Mar 29 '19 15:03

CodeGeek


People also ask

How do I get my Iphone to automatically read OTP?

Go to Settings > Passwords, then select your account for the website or app. Tap Set Up Verification Code, then tap Enter Setup Key. Tap the Setup Key field, tap Paste, then tap OK. Tap the Verification Code field, then tap Copy Verification Code.

How do you autofill in SMS flutter?

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 .


1 Answers

Check out this plugin. https://pub.dev/packages/sms_autofill#-readme-tab-

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.

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 know the plugin that it need 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.

like image 159
Rudresh Narwal Avatar answered Oct 10 '22 12:10

Rudresh Narwal