surfstudio / flutter-otp-autofill

Made by Surf 🏄
Apache License 2.0
81 stars 43 forks source link

[BUG] OTP Autofill Not Detected While Phone Number is Detected #100

Open bhanuka96 opened 2 months ago

bhanuka96 commented 2 months ago

Expected Behavior

The OTP autofill feature should detect and automatically populate the OTP code when it is received.

Actual Behavior

The phone number is detected successfully, but the OTP is not automatically detected or populated in the app. I tried both startListenUserConsent and startListenRetriever

Steps to Reproduce

  1. Set up OTP autofill using OTPTextEditController.
  2. Phone number detection works as expected.
  3. Receive OTP but it is not detected or autofilled into the OTP input field.

Details

Sample SMS

Your Firebase App verification code is 123456 signature_code_here

Full Code

class PhoneDetector {
  final OTPInteractor _otpInteractor = OTPInteractor();
  late OTPTextEditController controller;

  void detectPhoneNumber() {
      _otpInteractor.hint.then(phoneDetector);
  }

  void getSignature() {
      _otpInteractor.getAppSignature().then((signature) {
        debugPrint('Your app signature:$signature');
      });
  }

  void phoneDetector(String? value) {
      final _phone = value.getMobileNumberAuto(countryCode);
  }

  void listenForCode() {
      controller = OTPTextEditController(
        codeLength: 6,
        onCodeReceive: (code) {
          if (code.isEmpty) return;
          codeUpdated(code);
        },
        otpInteractor: _otpInteractor,
        onTimeOutException: () {
          controller.startListenRetriever(
            (code) {
              final exp = RegExp(r'(\d{6})');
              return exp.stringMatch(code ?? '') ?? '';
            },
          );
        },
      )..startListenRetriever(
          (code) {
            final exp = RegExp(r'(\d{6})');
            return exp.stringMatch(code ?? '') ?? '';
          },
        );
  }

  // @override
  void codeUpdated(String code) {
      debugPrint('SMS AUTOFILL CODE:$code');
  }

  void detectorDispose() {
      controller.stopListen();
  }
}

What Did You Try to Solve

Checklist for Self-Check

github-actions[bot] commented 2 months ago

Link to Pyrus task