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:
This will listen for the SMS with the code during 5 minutes and when received, autofill the following widget.
PinFieldAutoFill( decoration: // UnderlineDecoration, BoxLooseDecoration or BoxTightDecoration see https://github.com/TinoGuo/pin_input_text_field for more info, currentCode: // prefill with a code onCodeSubmitted: //code submitted callback onCodeChanged: //code changed callback codeLength: //code length, default 6 ),
TextFieldPinAutoFill( decoration: // basic InputDecoration currentCode: // prefill with a code onCodeSubmitted: //code submitted callback onCodeChanged: //code changed callback codeLength: //code length, default 6 ),
Android SMS constraint
For the code to be receive, it need to follow some rules as describe here: https://developers.google.com/identity/sms-retriever/verify
- Be no longer than 140 bytes
- Begin with the prefix <#>
- Contain a one-time code that the client sends back to your server to complete the verification flow
- End with an 11-character hash string that identifies your app
One example of SMS would be:
<#> ExampleApp: Your code is 123456 FA+9qCX9VSu
PhoneFieldHint is a widget that will allow you ask for system phone number and autofill the widget if a phone is choosen by the user.
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
cancel()to dispose the subscription of the SMS code from the native plugin, need to be called on your
codeUpdated()called when the code is received, you can access the value with the field
- Built-in types and core primitives for a Flutter application. [...]
- Support for asynchronous programming, with classes such as Future and Stream. [...]
- Classes and utilities that supplement the collection support in dart:core. [...]
- Encoders and decoders for converting between different data representations, including JSON and UTF-8. [...]
- Built-in types, collections, and other core functionality for every Dart program. [...]
- Interact with developer tools such as the debugger and inspector. [...]
- Mathematical constants and functions, plus a random number generator. [...]
- Lists that efficiently handle fixed sized data (for example, unsigned 8 byte integers) and SIMD numeric types. [...]
- File, socket, HTTP, and other I/O support for non-web applications. [...]
- Concurrent programming using isolates: independent workers that are similar to threads but don't share memory, communicating only via messages. [...]