OtpCodeVerificationField constructor
const
OtpCodeVerificationField({
- int numberOfDigits = 6,
- OtpCodeType? codeType,
- OtpCodeLetterCasing? codeLetterCasing,
- OtpCodeLetterSet? codeLetterSet,
- String customSet = '',
- bool autoFocus = true,
- ValueChanged<
String> ? onChanged, - required Future<
bool> onSubmit(- String code
- bool showCountdown = true,
- required DateTime? countdownStartDateTime,
- Duration countdownDuration = const Duration(minutes: 30),
- required VoidCallback onExpiredGoBack,
- bool showWrongCodeMessage = true,
- String wrongCodeMessage = 'Enter the correct code',
- String verificationFailedMessageBuilder({
- Object? error,
- String retryButtonLabel = 'Retry',
- String expiredMessage = 'Your code expired',
- String expiredButtonLabel = 'Go back to try again',
- String countdownTextBuilder({
- required int secondsCountdown,
- Widget countdownContainerBuilder({
- required Widget child,
- Widget errorContainerBuilder({
- required Widget child,
- Widget digitContainerBuilder({
- required Color? activeBorderColor,
- required Color? backgroundColor,
- required Color? borderColor,
- required Widget child,
- required bool isCurrentDigit,
- Widget buttonBuilder({
- required Color? backgroundColor,
- required String label,
- required VoidCallback onTap,
- required Color? textColor,
- required TextStyle? textStyle,
- TextStyle? digitTextStyle,
- TextStyle? errorTextStyle,
- TextStyle? expiredTextStyle,
- TextStyle? countdownTextStyle,
- TextStyle? buttonTextStyle,
- Color? digitBackgroundColor,
- Color? digitBorderColor,
- Color? digitActiveBorderColor,
- Color? cursorColor,
- Size? cursorSize = const Size(3, 30),
- Color? buttonBackgroundColor,
- Color? buttonTextColor,
- bool debugShowTextField = false,
- Key? key,
Implementation
const OtpCodeVerificationField({
this.numberOfDigits = 6,
this.codeType,
this.codeLetterCasing,
this.codeLetterSet,
this.customSet = '',
this.autoFocus = true,
this.onChanged,
required this.onSubmit,
this.showCountdown = true,
required this.countdownStartDateTime,
this.countdownDuration = const Duration(minutes: 30),
required this.onExpiredGoBack,
this.showWrongCodeMessage = true,
this.wrongCodeMessage = 'Enter the correct code',
this.verificationFailedMessageBuilder = defaultVerificationFailedMessageBuilder,
this.retryButtonLabel = 'Retry',
this.expiredMessage = 'Your code expired',
this.expiredButtonLabel = 'Go back to try again',
this.countdownTextBuilder = defaultCountdownText,
this.countdownContainerBuilder = defaultCountdownContainerBuilder,
this.errorContainerBuilder = defaultErrorContainerBuilder,
this.digitContainerBuilder = defaultDigitContainerBuilder,
this.buttonBuilder,
this.digitTextStyle,
this.errorTextStyle,
this.expiredTextStyle,
this.countdownTextStyle,
this.buttonTextStyle,
this.digitBackgroundColor,
this.digitBorderColor,
this.digitActiveBorderColor,
this.cursorColor,
this.cursorSize = const Size(3, 30),
this.buttonBackgroundColor,
this.buttonTextColor,
this.debugShowTextField = false,
super.key,
}) : assert(
numberOfDigits >= 2 && numberOfDigits <= 50,
'numberOfDigits must be in [2, 50]',
),
assert(
codeLetterSet != OtpCodeLetterSet.custom || customSet != '',
'customSet must be non-empty when codeLetterSet is OtpCodeLetterSet.custom',
),
// aToZ / unicodeLetters / custom are letter-portion sets — they
// can't be combined with codeType=numbersOnly (no letters allowed).
assert(
(codeLetterSet != OtpCodeLetterSet.aToZ &&
codeLetterSet != OtpCodeLetterSet.unicodeLetters &&
codeLetterSet != OtpCodeLetterSet.custom) ||
codeType != OtpCodeType.numbersOnly,
'codeLetterSet aToZ / unicodeLetters / custom requires codeType '
'to be lettersOnly, numbersAndLetters, or null',
),
// binary is digits-only; codeType must be numbersOnly or null.
assert(
codeLetterSet != OtpCodeLetterSet.binary ||
codeType == null ||
codeType == OtpCodeType.numbersOnly,
'codeLetterSet binary requires codeType to be numbersOnly or null',
),
// crockford / hexadecimal / base62 mix digits and letters; codeType
// must be numbersAndLetters or null.
assert(
(codeLetterSet != OtpCodeLetterSet.crockford &&
codeLetterSet != OtpCodeLetterSet.hexadecimal &&
codeLetterSet != OtpCodeLetterSet.base62) ||
codeType == null ||
codeType == OtpCodeType.numbersAndLetters,
'codeLetterSet crockford / hexadecimal / base62 requires codeType '
'to be numbersAndLetters or null',
),
// base62 keeps both cases distinct; forced casing would defeat it.
assert(
codeLetterSet != OtpCodeLetterSet.base62 ||
codeLetterCasing == null ||
codeLetterCasing == OtpCodeLetterCasing.mixed,
'codeLetterSet base62 requires codeLetterCasing to be mixed or null',
);