Skip to content

Instantly share code, notes, and snippets.

@maheshmnj
Last active April 19, 2021 13:24
Show Gist options
  • Save maheshmnj/7e840b84964b4bdbf723f471f9bc49cc to your computer and use it in GitHub Desktop.
Save maheshmnj/7e840b84964b4bdbf723f471f9bc49cc to your computer and use it in GitHub Desktop.
Auto Fill otp using sms_auto_fill flutter package
  1. Add the dependency https://pub.dev/packages/sms_autofill
  2. your class must implement the mixi CodeAutoFill mixin
  3. in initstate you should generate the app Signature and listen for the code
@override
  void initState() {
    listenForCode();
      SmsAutoFill().getAppSignature.then((signature) {
      setState(() {
        appSignature = signature;
        print(appSignature);
      });
    });
    super.initState();
}
  1. In the overriden method
 @override
  void codeUpdated() {
    // TODO: implement codeUpdated
    setState(() {
      otpController.text = code;
    });
    verifyOtp(code);
  }

  @override
  void dispose() {
    cancel();
    if (_shouldDisposeController) {
      controller.dispose();
    }
    unregisterListener();
    super.dispose();
  }

ANd the bakend should send tge otp in this format

<#> ExampleApp: Your code is 123456
FA+9qCX9VSu

where FA+.. is the appSignature generated in step 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment