VeryGoodOpenSource / VeryGoodOpenSource/formz
A validator of type Future
Nobody has claimed this yet.
- Dominant language
- Dart
- Stars
- 487
- Forks
- 42
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 2
Description
Hello,
I'm trying to use Formz to validate a phonenumber using the https://pub.dev/packages/libphonenumber library.
But libphonenumber's validation function returns a Future, so I was unable to use it in the validator() function of Formz
import 'package:formz/formz.dart';
import 'package:libphonenumber/libphonenumber.dart';
enum PhoneNumberValidationError { invalid }
class PhoneNumber extends FormzInput<String, PhoneNumberValidationError> {
const PhoneNumber.pure() : super.pure('');
const PhoneNumber.dirty([String value = '']) : super.dirty(value);
static final _phoneNumberRegex = RegExp(r'^[+]{1}[0-9]{1,4}[-\s\./0-9]*$');
@override
PhoneNumberValidationError validator(String value) {
return PhoneNumberUtil.isValidPhoneNumber(phoneNumber: "", isoCode: 'US').then((value){
return null;
});
}
}
error: A value of type 'Future<Null>' can't be returned from method 'validator' because it has a return type of 'PhoneNumberValidationError'. (return_of_invalid_type at [datoraid] lib/models/phone_number.dart:16)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the FormzInput validator contract and the example in lib/models/phone_number.dart. Confirm how the synchronous return type conflicts with libphonenumber's Future, then define the desired async-validation API and its completion criteria with maintainers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100