Search code examples
dartfluttertextfield

how to detect otp text in textfield flutter


How can I make auto detect otp text of my textfield in flutter I am not getting anything appropriate. Thanks in andvance.

 Center(
              child: Padding(
                padding: const EdgeInsets.only(top: 10.0),
                child:TextField(
                  controller: otpController,
                  maxLength: 6,
                  maxLengthEnforced: true,
                  textAlign: TextAlign.center,
                  decoration: InputDecoration(
                    border: InputBorder.none,
                    hintText: "_ _ _ _ _ _",
                    hintStyle: new TextStyle(
                      fontWeight: FontWeight.bold
                    )

//          border:
//          OutlineInputBorder(borderRadius: BorderRadius.circular(32.0))
                  ),
                  style: new TextStyle(
                    color: Colors.black,
                    fontWeight: FontWeight.bold,
                    fontSize: 22.0,
                  ),
                ),
              ),
            ),

Solution

  • You can use the sms_autofill plugin to automatically fill the PinFieldAutoFill with the OTP. To listen for OTP code change, you can use the onCodeChanged property.