Tkko / Flutter_Pinput

Flutter package to create Pin code input text field with every pixel customization possibility 🎨 with beautiful animations, iOS autofill, Android autofill
https://pub.dev/packages/pinput
MIT License
700 stars 172 forks source link

validator can use async #136

Closed nattawutxp closed 10 months ago

nattawutxp commented 1 year ago

I want pinput to be able to use async in the validator step.

Tkko commented 1 year ago

You can use forceErrorState property:

class ErrorStateExample extends StatefulWidget {
  const ErrorStateExample({Key? key}) : super(key: key);

  @override
  State<ErrorStateExample> createState() => _ErrorStateExampleState();
}

class _ErrorStateExampleState extends State<ErrorStateExample> {
  bool _hasError = false;

  Future<void> _validate(String value) async {
    await Future.delayed(const Duration(seconds: 2));
    setState(() => _hasError = value == '1111');
  }

  @override
  Widget build(BuildContext context) {
    return Pinput(
      forceErrorState: _hasError,
      onCompleted: _validate,
    );
  }
}
Tkko commented 10 months ago

Closing the issue for now because of inactivity, feel free to reopen if needed.