Coder Social home page Coder Social logo

flutter-otp-autofill's Introduction

OTP autofill

Made by Surf ๐Ÿ„โ€โ™‚๏ธ๐Ÿ„โ€โ™‚๏ธ๐Ÿ„โ€โ™‚๏ธ

Build Status Coverage Status Pub Version Pub Likes Pub popularity Flutter Platform

Overview

This plugin uses the SMS User Consent API and SMS Retriever API on Android.

You could use autofill from another input by using the OTPStrategy (e.g. from push-notification).

For testing you could create a TestStrategy.

iOS

On iOS, the OTP autofill feature is integrated into the TextField component. The code received from an SMS is stored for a duration of 3 minutes.

Rules for sms

  1. Sms must contain the word code or its translation in iOS supported localizations.
  2. The sms should contain only one sequence of digits.

iOS Testing

The iOS platform is capable of receiving OTP from any phone number, not just a specific sender.

Android

  • OTPInteractor.hint - displays a system dialog that allows the user to select from their saved phone numbers (recommendation from Google).
  • OTPInteractor.getAppSignature - creates the hash code of your application, which is used in the SMS Retriever API.
  • OTPInteractor.startListenUserConsent - the broadcast receiver that starts listening for OTP codes using the SMS User Consent API. It listens for a duration of 5 minutes, after which a timeout exception occurs.
  • OTPInteractor.startListenRetriever - the broadcast receiver that starts listening for OTP codes using the SMS Retriever API. It listens for a duration of 5 minutes, after which a timeout exception occurs.
  • OTPInteractor.stopListenForCode - used in dispose.

The plugin is designed to receive the full text of an SMS message and requires a parser to extract the relevant information from the message.

If you use the SMS User Consent API, the system will prompt the user for permission to access and read incoming messages.

Rules for SMS when using SMS User Consent API

  1. The message should contain an alphanumeric string of 4 to 10 characters, with at least one digit.
  2. The message was sent from a phone number that is not in the user's contacts.
  3. If the sender's phone number is specified, the message must originate from that number.

Rules for SMS when using SMS Retriever API

  1. The length should not exceed 140 bytes.
  2. It should contain a one-time code that the client sends back to your server to complete the verification process.
  3. It should include an 11-character hash string that identifies your app (refer to the documentation for server for more details). For testing, you can obtain it from OTPInteractor.getAppSignature.

Android Testing

The OTPInteractor.startListenForCode method allows the application to start receiving verification codes from a specific phone number, specified by the senderPhone argument.

Usage

You should use OTPInteractor to interact with OTP.

To simplify implementation, consider using the OTPTextEditController as a controller for your TextField.

OTPTextEditController.startListenUserConsent - uses the SMS User Consent API and listens to user strategies. OTPTextEditController.startListenRetriever - uses the SMS Retriever API and listens to user strategies. OTPTextEditController.startListenOnlyStrategies - only listens to user strategies. OTPTextEditController.stopListen - used in dispose.

Installation

Add otp_autofill to your pubspec.yaml file:

dependencies:
  otp_autofill: $currentVersion$

At this moment, the current version of otp_autofill is otp_autofill version.

Android Installation

Set minSdkVersion at least to 19 in <project root>/android/app/build.gradle.

android {
  ...
  defaultConfig {
    ...
    minSdkVersion 19
    ...
  }
  ...
}

Example

  1. Create a simple strategy
class SampleStrategy extends OTPStrategy {
  @override
  Future<String> listenForCode() {
    return Future.delayed(
      const Duration(seconds: 4),
      () => 'Your code is 54321',
    );
  }
}
  1. Initialize and set the listener
late OTPTextEditController controller;
final scaffoldKey = GlobalKey();

@override
void initState() {
  super.initState();
  _otpInteractor = OTPInteractor();
  _otpInteractor.getAppSignature()
      .then((value) => print('signature - $value'));
  controller = OTPTextEditController(
    codeLength: 5,
    onCodeReceive: (code) => print('Your Application receive code - $code'),
  )..startListenUserConsent(
      (code) {
        final exp = RegExp(r'(\d{5})');
        return exp.stringMatch(code ?? '') ?? '';
      },
      strategies: [
        SampleStrategy(),
      ],
    );
}

Send new code

To receive a new code when a timeout exception occurs, you can pass a callback function to the onTimeOutException parameter and start listen for a new code.

controller = OTPTextEditController(
      codeLength: 5,
      onCodeReceive: (code) => print('Your Application receive code - $code'),
      otpInteractor: _otpInteractor,
      onTimeOutException: () {
        //TODO: start new listen to get new code
        controller.startListenUserConsent(
          (code) {
            final exp = RegExp(r'(\d{5})');
            return exp.stringMatch(code ?? '') ?? '';
          },
          strategies: [
            SampleStrategy(),
          ],
        );
      },
    )..startListenUserConsent(
        (code) {
          final exp = RegExp(r'(\d{5})');
          return exp.stringMatch(code ?? '') ?? '';
        },
        strategies: [
          TimeoutStrategy(),
        ],
      );

Changelog

All significant changes to this project will be documented in this file.

Issues

To report any issues, submit them directly in the Issues section.

Contribute

If you wish to contribute to the package (for instance, by enhancing the documentation, fixing a bug, or introducing a new feature), please review our contribution guide first and then submit your pull request.

Your PRs are always welcome.

How to reach us

Please don't hesitate to ask any questions about this package. Join our community chat on Telegram. We communicate in both English and Russian.

Telegram

License

Apache License, Version 2.0

flutter-otp-autofill's People

Contributors

danyaao avatar dkrutskikh avatar dmitrdomrachev avatar feduke-nukem avatar galimzyanovdanil avatar ilyasov-ainur avatar internetova avatar kristinazoteva avatar mark-kascheev avatar martynov-alex avatar maxim-sysoev avatar mbixjkee avatar plasticfiresam avatar tinted-knight avatar vvpak avatar zaharovroman avatar zhukeev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

flutter-otp-autofill's Issues

[crash] com.google.android.gms.common.api.ApiException: 16

The otp_autofill:3.0.0 (latest) version, cause the crash on some Android devices.

Fatal Exception: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { (has extras) }} to activity {sg.partying.android.lite/com.imbb.banban.android.MainActivity}: com.google.android.gms.common.api.ApiException: 16:
at android.app.ActivityThread.deliverResults(ActivityThread.java:4458)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4500)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1839)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6861)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

Caused by com.google.android.gms.common.api.ApiException: 16:
at com.google.android.gms.internal.auth-api.zbay.getPhoneNumberFromIntent(com.google.android.gms:play-services-auth@@20.6.0:4)
at ru.surfstudio.otp_autofill.OTPPlugin.onActivityResult(OTPPlugin.kt:134)
at io.flutter.embedding.engine.FlutterEngineConnectionRegistry$FlutterEngineActivityPluginBinding.onActivityResult(FlutterEngineConnectionRegistry.java:807)
at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.onActivityResult(FlutterEngineConnectionRegistry.java:430)
at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onActivityResult(FlutterActivityAndFragmentDelegate.java:811)
at io.flutter.embedding.android.FlutterActivity.onActivityResult(FlutterActivity.java:771)
at android.app.Activity.dispatchActivityResult(Activity.java:7598)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4451)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4500)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1839)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6861)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

update kotlin to 1.7.10

The Android Gradle plugin supports only Kotlin Gradle plugin version 1.5.20 and higher.
The following dependencies do not satisfy the required version:
project ':otp_autofill' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50

[BUG] app is crashing

E/AndroidRuntime(21724): java.lang.RuntimeException: Unable to start receiver com.oohyugi.sms_otp_auto_verify.SmsBroadcastReceiver: java.lang.NullPointerException: null cannot be cast to non-null type kotlin.String app is crashing reciveing on otp

[ BUG ] [ IOS ] getAppSignature

Describe the bug

Getting runtime error on calling .getAppSignature

_otpInteractor = OTPInteractor();
_otpInteractor.getAppSignature()

Unhandled Exception: Instance of 'UnsupportedPlatform'

Error receiving broadcast intent

E/AndroidRuntime(26204): java.lang.RuntimeException: Error receiving broadcast Intent { act=com.google.android.gms.auth.api.phone.SMS_RETRIEVED flg=0x200010 pkg=in.kreateworld.debug (has extras) } in ru.surfstudio.otp_autofill.SmsRetrieverReceiver@130b2f0
E/AndroidRuntime(26204): 	at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1590)
E/AndroidRuntime(26204): 	at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2)
E/AndroidRuntime(26204): 	at android.os.Handler.handleCallback(Handler.java:938)
E/AndroidRuntime(26204): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(26204): 	at android.os.Looper.loop(Looper.java:223)
E/AndroidRuntime(26204): 	at android.app.ActivityThread.main(ActivityThread.java:7705)
E/AndroidRuntime(26204): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(26204): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/AndroidRuntime(26204): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:952)
E/AndroidRuntime(26204): Caused by: java.lang.IllegalStateException: Reply already submitted
E/AndroidRuntime(26204): 	at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:286)
E/AndroidRuntime(26204): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:267)
E/AndroidRuntime(26204): 	at ru.surfstudio.otp_autofill.OTPPlugin$registerSmsRetrieverBroadcastReceiver$1$1.onSuccess(OTPPlugin.kt:181)
E/AndroidRuntime(26204): 	at ru.surfstudio.otp_autofill.SmsRetrieverReceiver.onReceive(SmsRetrieverReceiver.kt:24)
E/AndroidRuntime(26204): 	at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1580)
E/AndroidRuntime(26204): 	... 8 more

Describe the bug

Once OTP sms is received, the app crashes completely. Code used is the same as that given in the example.

Additional context

I have forked this repo and added try catch around the android code, and upgraded the dependency versions in gradle, and it is working. That is not the proper way to do this though, just an emergency workaround.

Implementation of OTP autofill for Harmony OS

What is the new or updated feature that you are suggesting?

Supporting Harmony OS.

Why should this feature be included?

All existing solutions for implementing SMS autofill are based on ReadSmsManager, which is missing in the current version of HMS Core. Perhaps this is because HarmonyOS Next is currently being actively developed. BTW ReadSmsManager was also marked as deprecated in huawei_account plugin for Flutter.

At the moment it is not clear how this can be implemented, but I would really like to see work with Harmony OS as part of the package.

[BUG] Android App crashes when phone allowed two SMS at the same time.

Describe the bug

When the android phone receives two SMS at the same time, and the user allows the two OTPs, the app crashes.
Below is the error found in the logs.

E/AndroidRuntime( 4770): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { (has extras) }} to activity {com.sample.app/com.sample.app.MainActivity}: java.lang.IllegalStateException: Reply already submitted
E/AndroidRuntime( 4770): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:5506)
E/AndroidRuntime( 4770): 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:5547)
E/AndroidRuntime( 4770): 	at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
E/AndroidRuntime( 4770): 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E/AndroidRuntime( 4770): 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E/AndroidRuntime( 4770): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
E/AndroidRuntime( 4770): 	at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime( 4770): 	at android.os.Looper.loop(Looper.java:246)
E/AndroidRuntime( 4770): 	at android.app.ActivityThread.main(ActivityThread.java:8506)
E/AndroidRuntime( 4770): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 4770): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
E/AndroidRuntime( 4770): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
E/AndroidRuntime( 4770): Caused by: java.lang.IllegalStateException: Reply already submitted
E/AndroidRuntime( 4770): 	at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:164)
E/AndroidRuntime( 4770): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:238)
E/AndroidRuntime( 4770): 	at ru.surfstudio.otp_autofill.OTPPlugin.onActivityResult(OTPPlugin.kt:122)
E/AndroidRuntime( 4770): 	at io.flutter.embedding.engine.FlutterEngineConnectionRegistry$FlutterEngineActivityPluginBinding.onActivityResult(FlutterEngineConnectionRegistry.java:741)
E/AndroidRuntime( 4770): 	at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.onActivityResult(FlutterEngineConnectionRegistry.java:426)
E/AndroidRuntime( 4770): 	at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onActivityResult(FlutterActivityAndFragmentDelegate.java:749)
E/AndroidRuntime( 4770): 	at io.flutter.embedding.android.FlutterActivity.onActivityResult(FlutterActivity.java:651)
E/AndroidRuntime( 4770): 	at android.app.Activity.dispatchActivityResult(Activity.java:8541)
E/AndroidRuntime( 4770): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:5499)
E/AndroidRuntime( 4770): 	... 11 more
I/Process ( 4770): Sending signal. PID: 4770 SIG: 9

Steps to Reproduce

  1. Send SMS to the phone at the same time.
  2. Two user consent modals will show.
  3. Click the allow button on the two modals.

What is the expected behavior?

The app should not crash when clicking the allow button and the latest OTP must be displayed on the field.

Need to update the Koltin version to minimum 1.5.20

As flutter version is upgraded to 3.10.5 & Dart version 3.0.5 because of flutter & dart version is upgraded while building the app we are getting minimum kotlin version error.

Currently I am doing it manually.

Thanks.

java.lang.IllegalStateException: Reply already submitted[BUG]

The otp_autofill: 2.1.0 (latest) version, cause the crash on some Android devices. You can view the full error message bellow. The error is collected from the FirebaseCrashlytics.

Caused by java.lang.IllegalStateException: Reply already submitted
at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:35)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:14)
at ru.surfstudio.otp_autofill.OTPPlugin.onActivityResult(OTPPlugin.java:23)
at io.flutter.embedding.engine.FlutterEngineConnectionRegistry$FlutterEngineActivityPluginBinding.onActivityResult(FlutterEngineConnectionRegistry.java:25)
at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.onActivityResult(FlutterEngineConnectionRegistry.java:13)
at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onActivityResult(FlutterActivityAndFragmentDelegate.java:51)
at io.flutter.embedding.android.FlutterFragment.onActivityResult(FlutterFragment.java:10)
at io.flutter.embedding.android.FlutterFragmentActivity.onActivityResult(FlutterFragmentActivity.java:5)
at android.app.Activity.dispatchActivityResult(Activity.java:7743)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4744)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4793)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:113)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:71)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2054)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:233)
at android.app.ActivityThread.main(ActivityThread.java:7225)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:499)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:962)

java.lang.RuntimeException: Error receiving broadcast Intent { act=com.google.android.gms.auth.api.phone.SMS_RETRIEVED

java.lang.RuntimeException: Error receiving broadcast Intent { act=com.google.android.gms.auth.api.phone.SMS_RETRIEVED flg=0x200010 pkg=privpay.siriyangu.co.ke.privpay (has extras) } in ru.surfstudio.otp_autofill.SmsRetrieverReceiver@c5e4919 E/AndroidRuntime(19746): at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1561) E/AndroidRuntime(19746): at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2) E/AndroidRuntime(19746): at android.os.Handler.handleCallback(Handler.java:883) E/AndroidRuntime(19746): at android.os.Handler.dispatchMessage(Handler.java:100) E/AndroidRuntime(19746): at android.os.Looper.loop(Looper.java:264) E/AndroidRuntime(19746): at android.app.ActivityThread.main(ActivityThread.java:7684) E/AndroidRuntime(19746): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(19746): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) E/AndroidRuntime(19746): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980) E/AndroidRuntime(19746): Caused by: java.lang.IllegalStateException: Reply already submitted E/AndroidRuntime(19746): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:431) E/AndroidRuntime(19746): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:267) E/AndroidRuntime(19746): at ru.surfstudio.otp_autofill.OTPPlugin$registerSmsRetrieverBroadcastReceiver$1$1.onSuccess(OTPPlugin.kt:181) E/AndroidRuntime(19746): at ru.surfstudio.otp_autofill.SmsRetrieverReceiver.onReceive(SmsRetrieverReceiver.kt:24) E/AndroidRuntime(19746): at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1551) E/AndroidRuntime(19746): ... 8 more I/Process (19746): Sending signal. PID: 19746 SIG: 9 Lost connection to device.

Not Support on Kotlin version 1.5.20 or higher

The Android Gradle plugin supports only Kotlin Gradle plugin version 1.5.20 and higher.
The following dependencies do not satisfy the required version:
project ':otp_autofill' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50

[BUG] Kotlin Gradle plugin Support

  • What went wrong: The Android Gradle plugin supports only Kotlin Gradle plugin version 1.5.20 and higher. The following dependencies do not satisfy the required version: project ':otp_autofill' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50

No found otp_surfstudio

No implementation found for method getAppSignature on channel otp_surfstudio

what is this problem? how to fix ?

[BUG] Unhandled Exception on iOS if no additional strategies are provided

Expected behavior

Should handle empty strategies

Actual behavior

Throwing exception

Logs and stacktrace

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: On iOS OTP autofill is built in TextField. Code from sms stores for 3 minutes.(see Readme)
#0      OTPInteractor.startListenRetriever (package:otp_autofill/src/otp_interactor.dart:89:7)
#1      OTPTextEditController.startListenRetriever (package:otp_autofill/src/otp_text_edit_controller.dart:110:37)
#2     <REDACTED>
#3      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5602:55)
#4      ComponentElement.mount (package:flutter/src/widgets/framework.dart:5447:5)
#5      Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
#6      Element.updateChild (package:flutter/src/widgets/framework.dart:3837:18)
#7      SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6736:14)
#8      Element.inflateWidget (package:flutter/src/widgets/framework.dart:4326:16)
#9      Element.updateC<โ€ฆ>
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: Unexpected error: Bad state: No element
#0      OTPTextEditController.startListenRetriever.<anonymous closure> (package:otp_autofill/src/otp_text_edit_controller.dart:136:11)
#1      _FutureListener.handleError (dart:async/future_impl.dart:180:22)
#2      Future._propagateToListeners.handleError (dart:async/future_impl.dart:858:47)
#3      Future._propagateToListeners (dart:async/future_impl.dart:879:13)
#4      Future._completeError (dart:async/future_impl.dart:655:5)
#5      _completeWithErrorCallback (dart:async/future.dart:1334:10)
#6      Stream.first.<anonymous closure> (dart:async/stream.dart:1585:9)
#7      _RootZone.runGuarded (dart:async/zone.dart:1582:10)
#8      _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:392:13)
#9      _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:402:7)
#10     _BufferingStreamSubscription._close (dart:async/stream_impl.dart:291:7)
#<โ€ฆ>

OTP Send code again if haven't received any

Hello,
I'd like to know if there is a way for the user to get another code in the case he hasn't received any.
If no, would it be possible to integrate it please?
Regards.

How to implement SampleStrategy

hi, how to implement SampleStrategy for reading sms ?

class SampleStrategy extends OTPStrategy {
  @override
  Future<String> listenForCode() {
    return Future.delayed(
      const Duration(seconds: 4),
      () => 'Your code is 54321',
    );
  }
}

How to return sms content except 'Your code is 54321' - this string ?

[BUG] live app get firebase_auth sms received app close.

D/AndroidRuntime(26115): Shutting down VM
E/AndroidRuntime(26115): FATAL EXCEPTION: main
E/AndroidRuntime(26115): Process: com.cubicshoes, PID: 26115
E/AndroidRuntime(26115): java.lang.RuntimeException: Error receiving broadcast Intent { act=com.google.android.gms.auth.api.phone.SMS_RETRIEVED flg=0x200010 pkg=com.cubicshoes (has extras) } in com.google.android.gms.internal.firebase-auth-api.zzadx@97f0599
E/AndroidRuntime(26115): at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0(LoadedApk.java:1980)
E/AndroidRuntime(26115): at android.app.LoadedApk$ReceiverDispatcher$Args.$r8$lambda$gDuJqgxY6Zb-ifyeubKeivTLAwk(Unknown Source:0)
E/AndroidRuntime(26115): at android.app.LoadedApk$ReceiverDispatcher$Args$$ExternalSyntheticLambda0.run(Unknown Source:2)
E/AndroidRuntime(26115): at android.os.Handler.handleCallback(Handler.java:958)
E/AndroidRuntime(26115): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(26115): at android.os.Looper.loopOnce(Looper.java:257)
E/AndroidRuntime(26115): at android.os.Looper.loop(Looper.java:368)
E/AndroidRuntime(26115): at android.app.ActivityThread.main(ActivityThread.java:8825)
E/AndroidRuntime(26115): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(26115): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:572)
E/AndroidRuntime(26115): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
E/AndroidRuntime(26115): Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'int java.lang.CharSequence.length()' on a null object reference
E/AndroidRuntime(26115): at java.util.regex.Matcher.reset(Matcher.java:386)
E/AndroidRuntime(26115): at java.util.regex.Matcher.(Matcher.java:210)
E/AndroidRuntime(26115): at java.util.regex.Pattern.matcher(Pattern.java:989)
E/AndroidRuntime(26115): at com.google.android.gms.internal.firebase-auth-api.zzadt.zza(com.google.firebase:firebase-auth@@22.3.1:3)
E/AndroidRuntime(26115): at com.google.android.gms.internal.firebase-auth-api.zzadx.onReceive(com.google.firebase:firebase-auth@@22.3.1:13)
E/AndroidRuntime(26115): at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0(LoadedApk.java:1943)
E/AndroidRuntime(26115): ... 10 more
I/Process (26115): Sending signal. PID: 26115 SIG: 9
Lost connection to device.

[BUG] can't run/build app with the latest gradle version

Got this error when running the application with

compileSdkVersion 34
minSdkVersion 21

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

ext.kotlin_version = '1.8.22'
classpath 'com.android.tools.build:gradle:8.0.0'

What went wrong:
Execution failed for task ':otp_autofill:compileDebugKotlin'.
'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.
Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain

[BUG] Autofill OTP not working in Android 13.

Prior Issues

This package is working fine till android 12 but not working with Android 13.

Describe the bug

I am using this package and it's working fine but once i have update my device with android 13 and i have founded that this Package not able to read OTP in android 13.

Please help regarding any permission to add or update or use other package for support.

/// your code here

Steps to Reproduce

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?

A clear and concise description of what you expected to happen.

Additional context

  • What package and OS are affected by this issue? Did this work in previous versions of a package?

  • If applicable, add screenshots to help explain your problem.

  • Please provide output from flutter doctor -v and flutter analyze.

  • Add any other context about the problem here.

stopListen is not work

stopListen is not work. When close otp verification page, otp auto fill pop -up is arrive after stopListen called in dispose.

[QUESTION] Can I remove/hide the popup of SMS?

Can I remove or hide SMS pop-up?

If it is possible, can anyone explain it here?

I want SMS code to auto-populate without any system popups.
I attached a screenshot below of the content I want to hide.

Screenshot_2024-05-10-16-11-56-19_f7aa348215f5d566f9e4ca860f474209

Update Readme on pub.dev

In Example instead

  OTPInteractor.getAppSignature()
      .then((value) => print('signature - $value'));

it should be

    _otpInteractor = OTPInteractor();
    _otpInteractor
        .getAppSignature()
        .then((value) => print('signature - $value'));

And in Installation section instead otp-autofill it should be otp_autofill

Regenerating App Signature

Hi, I just wanted to know that is there any way to generate new signature of the application ?

Actually the problem with the once I got is that it contains a special character which is not accepted by the message service provider therefore startListenRetriever() is not working for me.

Any solution to this would be appreciated!.

Unable to import this package.

Prior Issues

Are there any existing issues or PRs that relate to this problem? If so, link them here.

Describe the bug

A clear and concise description of what the bug is.
Please show the code you wrote as completely as possible.

/// your code here

Steps to Reproduce

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?

A clear and concise description of what you expected to happen.

Additional context

  • What package and OS are affected by this issue? Did this work in previous versions of a package?

  • If applicable, add screenshots to help explain your problem.

  • Please provide output from flutter doctor -v and flutter analyze.

  • Add any other context about the problem here.

How to read a resend otp using this package

Describe what scenario you think is uncovered by the existing examples / articles

A clear and concise description of the problem that you want explained.

Describe why existing examples / articles do not cover this case

Explain which examples / articles you have seen before making this request, and
why they did not help you with your problem.

Additional context

Add any other context or screenshots about the documentation request here.

[BUG] OTP AutoFill hint

When i tried to implement hint (for number) isn't work. I see popup and then he quickly closed.

  @override
  void initState() {
    // TODO: implement initState
    saveCurrentRoute('$PhoneConnection');
    setRouteArray('$PhoneConnection', true);
    Future.delayed(Duration(milliseconds: 2000))
        .then((value) async => await getNumber());
    super.initState();
  }
Future<dynamic> getNumber() async {
    var _otpInteractor = OTPInteractor();
    String number = await _otpInteractor.hint;
    debugPrint('$number');
  }

Doctor summary (to see all details, run flutter doctor -v):
[โˆš] Flutter (Channel stable, 2.2.3, on Microsoft Windows [Version 10.0.22000.258], locale ru-RU)
[โˆš] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[โˆš] Chrome - develop for the web
[โˆš] Visual Studio - develop for Windows (Visual Studio Community 2022 17.0.0 RC2)
[!] Android Studio (not installed)
[โˆš] VS Code (version 1.61.2)
[โˆš] Connected device (4 available)

! Doctor found issues in 1 category.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.