otpField method

Widget otpField({
  1. required TextEditingController controller,
  2. required String hint,
  3. String? label,
  4. FormFieldValidator<String>? validator,
  5. ValueChanged<String>? onSubmitted,
  6. int? maxLength,
})

Single-field OTP input (kept for hosts that build their own layout).

Implementation

Widget otpField({
  required TextEditingController controller,
  required String hint,
  String? label,
  FormFieldValidator<String>? validator,
  ValueChanged<String>? onSubmitted,
  int? maxLength,
}) {
  final field = TextFormField(
    controller: controller,
    keyboardType: TextInputType.number,
    textAlign: TextAlign.center,
    style: otpTextStyle,
    maxLength: maxLength,
    obscureText: theme.otpHidden,
    inputFormatters: [FilteringTextInputFormatter.digitsOnly],
    decoration:
        (theme.inputUnderline
                ? underlineInputDecoration(hint: hint, label: label)
                : otpInputDecoration(hint: hint, label: label))
            .copyWith(counterText: ''),
    validator: validator,
    onFieldSubmitted: onSubmitted,
    autofillHints: const [AutofillHints.oneTimeCode],
  );
  return theme.inputUnderline ? field : decorateInput(field);
}