InputOTPChild.character constructor

InputOTPChild.character({
  1. bool allowLowercaseAlphabet = false,
  2. bool allowUppercaseAlphabet = false,
  3. bool allowDigit = false,
  4. bool obscured = false,
  5. bool onlyUppercaseAlphabet = false,
  6. bool onlyLowercaseAlphabet = false,
  7. bool readOnly = false,
  8. TextInputType? keyboardType,
})

Implementation

factory InputOTPChild.character({
  bool allowLowercaseAlphabet = false,
  bool allowUppercaseAlphabet = false,
  bool allowDigit = false,
  bool obscured = false,
  bool onlyUppercaseAlphabet = false,
  bool onlyLowercaseAlphabet = false,
  bool readOnly = false,
  TextInputType? keyboardType,
}) {
  assert(!(onlyUppercaseAlphabet && onlyLowercaseAlphabet),
      'onlyUppercaseAlphabet and onlyLowercaseAlphabet cannot be true at the same time');
  keyboardType ??= allowDigit &&
          !allowLowercaseAlphabet &&
          !allowUppercaseAlphabet &&
          !onlyUppercaseAlphabet &&
          !onlyLowercaseAlphabet
      ? TextInputType.number
      : TextInputType.text;
  return CharacterInputOTPChild(
    predicate: (codepoint) {
      if (allowLowercaseAlphabet &&
          CharacterInputOTPChild.isAlphabetLower(codepoint)) {
        return true;
      }
      if (allowUppercaseAlphabet &&
          CharacterInputOTPChild.isAlphabetUpper(codepoint)) {
        return true;
      }
      if (allowDigit && CharacterInputOTPChild.isDigit(codepoint)) {
        return true;
      }
      return false;
    },
    transform: (codepoint) {
      if (onlyUppercaseAlphabet) {
        return CharacterInputOTPChild.lowerToUpper(codepoint);
      }
      if (onlyLowercaseAlphabet) {
        return CharacterInputOTPChild.upperToLower(codepoint);
      }
      return codepoint;
    },
    keyboardType: keyboardType,
    obscured: obscured,
    readOnly: readOnly,
  );
}