Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Can make the validator function become a async function? #189

Open
cogivn opened this issue Jun 26, 2024 · 1 comment
Open

Comments

@cogivn
Copy link
Contributor

cogivn commented Jun 26, 2024

Hi,

Thank you for create an awesome package for flutter developer.

I am facing the problem is try to verify the otp code from server side but now the Pinput's validator only accept synchronize function
So, I open a ticket to request new feature that validator field can receive a async function or new mechanism to verify the OTP code from server side.

Pinput.builder(
                length: 6,
                controller: controller,
                focusNode: focusNode,
                autofocus: true,
                forceErrorState: state.status.isError,
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                onCompleted: context.read<SmsCubit>().verify,
                onChanged: context.read<SmsCubit>().inputting,
                hapticFeedbackType: HapticFeedbackType.lightImpact,
                pinputAutovalidateMode: PinputAutovalidateMode.disabled,
                validator: (pin) async => verifyFromServer(pin),
                separatorBuilder: (_) => const SizedBox(width: 1),
                builder: (_, pinState) {
                  return _PinItem(state: pinState);
                },
              ),
@andrijailic
Copy link

andrijailic commented Jun 27, 2024

I got here for similar problem, but it seems like there is a workaround -> #136.

You can supply onCompleted with async function and then, if validation on server fails, force this widget to go in error sate. I guess you should also set an errorText in that case and completely omit validator field.

I am not that happy with this solution (asyncValidator would be more elegant), but hey - it is what it is :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants