Create async validator in FlutterFlutter firebase validation of form field inputsHow would I run an async Task<T> method synchronously?How and when to use ‘async’ and ‘await’AngularJS : Initialize service with asynchronous dataChange CheckBox value with custom class propertyFlutter: Initialising variables on startupFlutter formfield abnormalityFlutter using http request to registerFlutter Class level variable bool not workingHow to refresh flutter UI on AlertDialog close?Fat Arrow notation with curly braces in setState Dart/Flutter
What happens when two cards both modify what I'm allowed to do?
Sometimes you are this word with three vowels
Why can't a country print its own money to spend it only abroad?
What exactly makes a General Products hull nearly indestructible?
How could an engineer advance human civilization by time traveling to the past?
Why does the salt in the oceans not sink to the bottom?
How important is a good quality camera for good photography?
How to write a sincerely religious protagonist without preaching or affirming or judging their worldview?
Raw curve25519 public key points
Why did NASA use Imperial units?
What is the spanish equivalent of "the boys are sitting"?
Monty Hall Problem with a Fallible Monty
When were "acrobatics" introduced at weddings?
What is "ass door"?
Is the apartment I want to rent a scam?
The seven story archetypes. Are they truly all of them?
Are gangsters hired to attack people at a train station classified as a terrorist attack?
Is there a way to factor age into the mass-luminosity relationship for stars?
Are symplectomorphisms of Weil–Petersson symplectic form induced from surface diffeomorphisms?
What's the explanation for this joke about a three-legged dog that walks into a bar?
How can I tell if there was a power cut when I was out?
Why did computer video outputs go from digital to analog, then back to digital?
how to add 1 milliseconds on a datetime string?
Issue with ContourPlot
Create async validator in Flutter
Flutter firebase validation of form field inputsHow would I run an async Task<T> method synchronously?How and when to use ‘async’ and ‘await’AngularJS : Initialize service with asynchronous dataChange CheckBox value with custom class propertyFlutter: Initialising variables on startupFlutter formfield abnormalityFlutter using http request to registerFlutter Class level variable bool not workingHow to refresh flutter UI on AlertDialog close?Fat Arrow notation with curly braces in setState Dart/Flutter
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have an asynchronous function in Flutter which takes the value of the validator as an argument:
validatePhone(number)
bool _isValid;
Requests.get("http://apilayer.net/api/validate?value=$number", json: true)
.then((val)
if (val['valid'])
// setState(() <- also tried setting state here
_isValid = true;
// );
else
// setState(()
_isValid = false;
// );
);
return _isValid;
and
TextFormField(
validator: (value)
if (value.isEmpty)
return 'Please your phone number';
else
if (validatePhone(value))
return 'Your phone number is not valid';
,
),
but it does not work it always returns null
or the initial value set in validatePhone
. Any idea how I can make this work?
asynchronous dart flutter
add a comment |
I have an asynchronous function in Flutter which takes the value of the validator as an argument:
validatePhone(number)
bool _isValid;
Requests.get("http://apilayer.net/api/validate?value=$number", json: true)
.then((val)
if (val['valid'])
// setState(() <- also tried setting state here
_isValid = true;
// );
else
// setState(()
_isValid = false;
// );
);
return _isValid;
and
TextFormField(
validator: (value)
if (value.isEmpty)
return 'Please your phone number';
else
if (validatePhone(value))
return 'Your phone number is not valid';
,
),
but it does not work it always returns null
or the initial value set in validatePhone
. Any idea how I can make this work?
asynchronous dart flutter
I'm new to Fluuter (3 days so be indulgent) but I think you need to update_isValid
inside thesetstate()
method. This method will rebuild the widget and modifiy the view.
– Maxouille
Mar 26 at 15:21
@Maxouille appreciate your honesty :D butsetState()
I also tried and it didn't work neither.
– supersize
Mar 26 at 15:22
1
Okay srry. Interested in the answer so :)
– Maxouille
Mar 26 at 15:23
Have you tried awaiting your code when you validate the phone number? If not the code execution may just continue without having actually validated if the string is a phone number.
– R. Duggan
Mar 26 at 15:36
1
If you want to check input asynchronously then you can use stream and block to do so.
– Viren V Varasadiya
Mar 26 at 15:47
add a comment |
I have an asynchronous function in Flutter which takes the value of the validator as an argument:
validatePhone(number)
bool _isValid;
Requests.get("http://apilayer.net/api/validate?value=$number", json: true)
.then((val)
if (val['valid'])
// setState(() <- also tried setting state here
_isValid = true;
// );
else
// setState(()
_isValid = false;
// );
);
return _isValid;
and
TextFormField(
validator: (value)
if (value.isEmpty)
return 'Please your phone number';
else
if (validatePhone(value))
return 'Your phone number is not valid';
,
),
but it does not work it always returns null
or the initial value set in validatePhone
. Any idea how I can make this work?
asynchronous dart flutter
I have an asynchronous function in Flutter which takes the value of the validator as an argument:
validatePhone(number)
bool _isValid;
Requests.get("http://apilayer.net/api/validate?value=$number", json: true)
.then((val)
if (val['valid'])
// setState(() <- also tried setting state here
_isValid = true;
// );
else
// setState(()
_isValid = false;
// );
);
return _isValid;
and
TextFormField(
validator: (value)
if (value.isEmpty)
return 'Please your phone number';
else
if (validatePhone(value))
return 'Your phone number is not valid';
,
),
but it does not work it always returns null
or the initial value set in validatePhone
. Any idea how I can make this work?
asynchronous dart flutter
asynchronous dart flutter
edited Mar 27 at 7:49
supersize
asked Mar 26 at 15:17
supersizesupersize
3,81911 gold badges39 silver badges79 bronze badges
3,81911 gold badges39 silver badges79 bronze badges
I'm new to Fluuter (3 days so be indulgent) but I think you need to update_isValid
inside thesetstate()
method. This method will rebuild the widget and modifiy the view.
– Maxouille
Mar 26 at 15:21
@Maxouille appreciate your honesty :D butsetState()
I also tried and it didn't work neither.
– supersize
Mar 26 at 15:22
1
Okay srry. Interested in the answer so :)
– Maxouille
Mar 26 at 15:23
Have you tried awaiting your code when you validate the phone number? If not the code execution may just continue without having actually validated if the string is a phone number.
– R. Duggan
Mar 26 at 15:36
1
If you want to check input asynchronously then you can use stream and block to do so.
– Viren V Varasadiya
Mar 26 at 15:47
add a comment |
I'm new to Fluuter (3 days so be indulgent) but I think you need to update_isValid
inside thesetstate()
method. This method will rebuild the widget and modifiy the view.
– Maxouille
Mar 26 at 15:21
@Maxouille appreciate your honesty :D butsetState()
I also tried and it didn't work neither.
– supersize
Mar 26 at 15:22
1
Okay srry. Interested in the answer so :)
– Maxouille
Mar 26 at 15:23
Have you tried awaiting your code when you validate the phone number? If not the code execution may just continue without having actually validated if the string is a phone number.
– R. Duggan
Mar 26 at 15:36
1
If you want to check input asynchronously then you can use stream and block to do so.
– Viren V Varasadiya
Mar 26 at 15:47
I'm new to Fluuter (3 days so be indulgent) but I think you need to update
_isValid
inside the setstate()
method. This method will rebuild the widget and modifiy the view.– Maxouille
Mar 26 at 15:21
I'm new to Fluuter (3 days so be indulgent) but I think you need to update
_isValid
inside the setstate()
method. This method will rebuild the widget and modifiy the view.– Maxouille
Mar 26 at 15:21
@Maxouille appreciate your honesty :D but
setState()
I also tried and it didn't work neither.– supersize
Mar 26 at 15:22
@Maxouille appreciate your honesty :D but
setState()
I also tried and it didn't work neither.– supersize
Mar 26 at 15:22
1
1
Okay srry. Interested in the answer so :)
– Maxouille
Mar 26 at 15:23
Okay srry. Interested in the answer so :)
– Maxouille
Mar 26 at 15:23
Have you tried awaiting your code when you validate the phone number? If not the code execution may just continue without having actually validated if the string is a phone number.
– R. Duggan
Mar 26 at 15:36
Have you tried awaiting your code when you validate the phone number? If not the code execution may just continue without having actually validated if the string is a phone number.
– R. Duggan
Mar 26 at 15:36
1
1
If you want to check input asynchronously then you can use stream and block to do so.
– Viren V Varasadiya
Mar 26 at 15:47
If you want to check input asynchronously then you can use stream and block to do so.
– Viren V Varasadiya
Mar 26 at 15:47
add a comment |
1 Answer
1
active
oldest
votes
As it was said in the comments, it is not possible to have async validators as validator
is expected to return a String
and not a `Future'.
However, there are a number of things that's wrong in your code. First of all, validatePhone
returns before _isValid
is set, which is why you're getting a null
value, because it was never set to anything. Your request completes after validatePhone
returns and setting _isValid
is useless at that point.
Let's try to fix validatePhone:
Future<bool> validatePhone(number) async
bool _isValid;
final val = await Requests.get(
"http://apilayer.net/api/validate?value=$number",
json: true);
if (val['valid'])
// setState(()
_isValid = true;
// );
else
// setState(()
_isValid = false;
// );
return _isValid;
as you see, it's return value had to become Future<bool>
, not bool
. There is no way to fix this. If validator
was allowed to return Future
, then it could work.
You're going to have to implement your validation logic in a custom painful way.
Edit: here comes a custom painful way :)
String lastValidatedNumber;
String lastRejectedNumber;
// this will be called upon user interaction or re-initiation as commented below
String validatePhone(String number)
if (lastValidatedNumber == number)
return null;
else if (lastRejectedNumber == number)
return "Phone number is invalid";
else
initiateAsyncPhoneValidation(number);
return "Validation in progress";
Future<void> initiateAsyncPhoneValidation(String number) async
final val = await Requests.get(
"http://apilayer.net/api/validate?value=$number",
json: true);
if (val['valid'])
lastValidatedNumber = number;
else
lastRejectedNumber = number;
_formKey.currentState.validate(); // this will re-initiate the validation
You need to have a form key:
final _formKey = GlobalKey<FormState>();
And your form should auto validate:
child: Form(
key: _formKey,
autovalidate: true,
child: TextFormField(
validator: validatePhone
)
)
I'm not 100% sure if this would work, but it's worth a shot.
so you're fixing my code but it still doesn't work, yeah? Maybe you could provide thecustom painful way
you are talking about :)
– supersize
Mar 26 at 16:39
I just wanted to show you what happens if you try to fix the code, and where you hit the wall with this approach. Good luck!
– Gazihan Alankus
Mar 26 at 18:51
Appreciate it but that's not an answer to this question
– supersize
Mar 27 at 7:46
I guess the answer is "validators can't be async". If you can explain your situation and why you really need an async validator, perhaps a better answer can follow.
– Gazihan Alankus
Mar 27 at 8:00
1
Right, that solution is missing the_formKey.currentState.validate();
, which is why you have to submit once more. If youautovalidate
, at every change a validation is triggered, which in turn asynchronously trigger a validation again after it has the answer. If you can tell me what happened with my answer I can try to help.
– Gazihan Alankus
Mar 27 at 10:50
|
show 12 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55360628%2fcreate-async-validator-in-flutter%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As it was said in the comments, it is not possible to have async validators as validator
is expected to return a String
and not a `Future'.
However, there are a number of things that's wrong in your code. First of all, validatePhone
returns before _isValid
is set, which is why you're getting a null
value, because it was never set to anything. Your request completes after validatePhone
returns and setting _isValid
is useless at that point.
Let's try to fix validatePhone:
Future<bool> validatePhone(number) async
bool _isValid;
final val = await Requests.get(
"http://apilayer.net/api/validate?value=$number",
json: true);
if (val['valid'])
// setState(()
_isValid = true;
// );
else
// setState(()
_isValid = false;
// );
return _isValid;
as you see, it's return value had to become Future<bool>
, not bool
. There is no way to fix this. If validator
was allowed to return Future
, then it could work.
You're going to have to implement your validation logic in a custom painful way.
Edit: here comes a custom painful way :)
String lastValidatedNumber;
String lastRejectedNumber;
// this will be called upon user interaction or re-initiation as commented below
String validatePhone(String number)
if (lastValidatedNumber == number)
return null;
else if (lastRejectedNumber == number)
return "Phone number is invalid";
else
initiateAsyncPhoneValidation(number);
return "Validation in progress";
Future<void> initiateAsyncPhoneValidation(String number) async
final val = await Requests.get(
"http://apilayer.net/api/validate?value=$number",
json: true);
if (val['valid'])
lastValidatedNumber = number;
else
lastRejectedNumber = number;
_formKey.currentState.validate(); // this will re-initiate the validation
You need to have a form key:
final _formKey = GlobalKey<FormState>();
And your form should auto validate:
child: Form(
key: _formKey,
autovalidate: true,
child: TextFormField(
validator: validatePhone
)
)
I'm not 100% sure if this would work, but it's worth a shot.
so you're fixing my code but it still doesn't work, yeah? Maybe you could provide thecustom painful way
you are talking about :)
– supersize
Mar 26 at 16:39
I just wanted to show you what happens if you try to fix the code, and where you hit the wall with this approach. Good luck!
– Gazihan Alankus
Mar 26 at 18:51
Appreciate it but that's not an answer to this question
– supersize
Mar 27 at 7:46
I guess the answer is "validators can't be async". If you can explain your situation and why you really need an async validator, perhaps a better answer can follow.
– Gazihan Alankus
Mar 27 at 8:00
1
Right, that solution is missing the_formKey.currentState.validate();
, which is why you have to submit once more. If youautovalidate
, at every change a validation is triggered, which in turn asynchronously trigger a validation again after it has the answer. If you can tell me what happened with my answer I can try to help.
– Gazihan Alankus
Mar 27 at 10:50
|
show 12 more comments
As it was said in the comments, it is not possible to have async validators as validator
is expected to return a String
and not a `Future'.
However, there are a number of things that's wrong in your code. First of all, validatePhone
returns before _isValid
is set, which is why you're getting a null
value, because it was never set to anything. Your request completes after validatePhone
returns and setting _isValid
is useless at that point.
Let's try to fix validatePhone:
Future<bool> validatePhone(number) async
bool _isValid;
final val = await Requests.get(
"http://apilayer.net/api/validate?value=$number",
json: true);
if (val['valid'])
// setState(()
_isValid = true;
// );
else
// setState(()
_isValid = false;
// );
return _isValid;
as you see, it's return value had to become Future<bool>
, not bool
. There is no way to fix this. If validator
was allowed to return Future
, then it could work.
You're going to have to implement your validation logic in a custom painful way.
Edit: here comes a custom painful way :)
String lastValidatedNumber;
String lastRejectedNumber;
// this will be called upon user interaction or re-initiation as commented below
String validatePhone(String number)
if (lastValidatedNumber == number)
return null;
else if (lastRejectedNumber == number)
return "Phone number is invalid";
else
initiateAsyncPhoneValidation(number);
return "Validation in progress";
Future<void> initiateAsyncPhoneValidation(String number) async
final val = await Requests.get(
"http://apilayer.net/api/validate?value=$number",
json: true);
if (val['valid'])
lastValidatedNumber = number;
else
lastRejectedNumber = number;
_formKey.currentState.validate(); // this will re-initiate the validation
You need to have a form key:
final _formKey = GlobalKey<FormState>();
And your form should auto validate:
child: Form(
key: _formKey,
autovalidate: true,
child: TextFormField(
validator: validatePhone
)
)
I'm not 100% sure if this would work, but it's worth a shot.
so you're fixing my code but it still doesn't work, yeah? Maybe you could provide thecustom painful way
you are talking about :)
– supersize
Mar 26 at 16:39
I just wanted to show you what happens if you try to fix the code, and where you hit the wall with this approach. Good luck!
– Gazihan Alankus
Mar 26 at 18:51
Appreciate it but that's not an answer to this question
– supersize
Mar 27 at 7:46
I guess the answer is "validators can't be async". If you can explain your situation and why you really need an async validator, perhaps a better answer can follow.
– Gazihan Alankus
Mar 27 at 8:00
1
Right, that solution is missing the_formKey.currentState.validate();
, which is why you have to submit once more. If youautovalidate
, at every change a validation is triggered, which in turn asynchronously trigger a validation again after it has the answer. If you can tell me what happened with my answer I can try to help.
– Gazihan Alankus
Mar 27 at 10:50
|
show 12 more comments
As it was said in the comments, it is not possible to have async validators as validator
is expected to return a String
and not a `Future'.
However, there are a number of things that's wrong in your code. First of all, validatePhone
returns before _isValid
is set, which is why you're getting a null
value, because it was never set to anything. Your request completes after validatePhone
returns and setting _isValid
is useless at that point.
Let's try to fix validatePhone:
Future<bool> validatePhone(number) async
bool _isValid;
final val = await Requests.get(
"http://apilayer.net/api/validate?value=$number",
json: true);
if (val['valid'])
// setState(()
_isValid = true;
// );
else
// setState(()
_isValid = false;
// );
return _isValid;
as you see, it's return value had to become Future<bool>
, not bool
. There is no way to fix this. If validator
was allowed to return Future
, then it could work.
You're going to have to implement your validation logic in a custom painful way.
Edit: here comes a custom painful way :)
String lastValidatedNumber;
String lastRejectedNumber;
// this will be called upon user interaction or re-initiation as commented below
String validatePhone(String number)
if (lastValidatedNumber == number)
return null;
else if (lastRejectedNumber == number)
return "Phone number is invalid";
else
initiateAsyncPhoneValidation(number);
return "Validation in progress";
Future<void> initiateAsyncPhoneValidation(String number) async
final val = await Requests.get(
"http://apilayer.net/api/validate?value=$number",
json: true);
if (val['valid'])
lastValidatedNumber = number;
else
lastRejectedNumber = number;
_formKey.currentState.validate(); // this will re-initiate the validation
You need to have a form key:
final _formKey = GlobalKey<FormState>();
And your form should auto validate:
child: Form(
key: _formKey,
autovalidate: true,
child: TextFormField(
validator: validatePhone
)
)
I'm not 100% sure if this would work, but it's worth a shot.
As it was said in the comments, it is not possible to have async validators as validator
is expected to return a String
and not a `Future'.
However, there are a number of things that's wrong in your code. First of all, validatePhone
returns before _isValid
is set, which is why you're getting a null
value, because it was never set to anything. Your request completes after validatePhone
returns and setting _isValid
is useless at that point.
Let's try to fix validatePhone:
Future<bool> validatePhone(number) async
bool _isValid;
final val = await Requests.get(
"http://apilayer.net/api/validate?value=$number",
json: true);
if (val['valid'])
// setState(()
_isValid = true;
// );
else
// setState(()
_isValid = false;
// );
return _isValid;
as you see, it's return value had to become Future<bool>
, not bool
. There is no way to fix this. If validator
was allowed to return Future
, then it could work.
You're going to have to implement your validation logic in a custom painful way.
Edit: here comes a custom painful way :)
String lastValidatedNumber;
String lastRejectedNumber;
// this will be called upon user interaction or re-initiation as commented below
String validatePhone(String number)
if (lastValidatedNumber == number)
return null;
else if (lastRejectedNumber == number)
return "Phone number is invalid";
else
initiateAsyncPhoneValidation(number);
return "Validation in progress";
Future<void> initiateAsyncPhoneValidation(String number) async
final val = await Requests.get(
"http://apilayer.net/api/validate?value=$number",
json: true);
if (val['valid'])
lastValidatedNumber = number;
else
lastRejectedNumber = number;
_formKey.currentState.validate(); // this will re-initiate the validation
You need to have a form key:
final _formKey = GlobalKey<FormState>();
And your form should auto validate:
child: Form(
key: _formKey,
autovalidate: true,
child: TextFormField(
validator: validatePhone
)
)
I'm not 100% sure if this would work, but it's worth a shot.
edited Mar 27 at 12:56
answered Mar 26 at 16:04
Gazihan AlankusGazihan Alankus
2,6681 gold badge14 silver badges26 bronze badges
2,6681 gold badge14 silver badges26 bronze badges
so you're fixing my code but it still doesn't work, yeah? Maybe you could provide thecustom painful way
you are talking about :)
– supersize
Mar 26 at 16:39
I just wanted to show you what happens if you try to fix the code, and where you hit the wall with this approach. Good luck!
– Gazihan Alankus
Mar 26 at 18:51
Appreciate it but that's not an answer to this question
– supersize
Mar 27 at 7:46
I guess the answer is "validators can't be async". If you can explain your situation and why you really need an async validator, perhaps a better answer can follow.
– Gazihan Alankus
Mar 27 at 8:00
1
Right, that solution is missing the_formKey.currentState.validate();
, which is why you have to submit once more. If youautovalidate
, at every change a validation is triggered, which in turn asynchronously trigger a validation again after it has the answer. If you can tell me what happened with my answer I can try to help.
– Gazihan Alankus
Mar 27 at 10:50
|
show 12 more comments
so you're fixing my code but it still doesn't work, yeah? Maybe you could provide thecustom painful way
you are talking about :)
– supersize
Mar 26 at 16:39
I just wanted to show you what happens if you try to fix the code, and where you hit the wall with this approach. Good luck!
– Gazihan Alankus
Mar 26 at 18:51
Appreciate it but that's not an answer to this question
– supersize
Mar 27 at 7:46
I guess the answer is "validators can't be async". If you can explain your situation and why you really need an async validator, perhaps a better answer can follow.
– Gazihan Alankus
Mar 27 at 8:00
1
Right, that solution is missing the_formKey.currentState.validate();
, which is why you have to submit once more. If youautovalidate
, at every change a validation is triggered, which in turn asynchronously trigger a validation again after it has the answer. If you can tell me what happened with my answer I can try to help.
– Gazihan Alankus
Mar 27 at 10:50
so you're fixing my code but it still doesn't work, yeah? Maybe you could provide the
custom painful way
you are talking about :)– supersize
Mar 26 at 16:39
so you're fixing my code but it still doesn't work, yeah? Maybe you could provide the
custom painful way
you are talking about :)– supersize
Mar 26 at 16:39
I just wanted to show you what happens if you try to fix the code, and where you hit the wall with this approach. Good luck!
– Gazihan Alankus
Mar 26 at 18:51
I just wanted to show you what happens if you try to fix the code, and where you hit the wall with this approach. Good luck!
– Gazihan Alankus
Mar 26 at 18:51
Appreciate it but that's not an answer to this question
– supersize
Mar 27 at 7:46
Appreciate it but that's not an answer to this question
– supersize
Mar 27 at 7:46
I guess the answer is "validators can't be async". If you can explain your situation and why you really need an async validator, perhaps a better answer can follow.
– Gazihan Alankus
Mar 27 at 8:00
I guess the answer is "validators can't be async". If you can explain your situation and why you really need an async validator, perhaps a better answer can follow.
– Gazihan Alankus
Mar 27 at 8:00
1
1
Right, that solution is missing the
_formKey.currentState.validate();
, which is why you have to submit once more. If you autovalidate
, at every change a validation is triggered, which in turn asynchronously trigger a validation again after it has the answer. If you can tell me what happened with my answer I can try to help.– Gazihan Alankus
Mar 27 at 10:50
Right, that solution is missing the
_formKey.currentState.validate();
, which is why you have to submit once more. If you autovalidate
, at every change a validation is triggered, which in turn asynchronously trigger a validation again after it has the answer. If you can tell me what happened with my answer I can try to help.– Gazihan Alankus
Mar 27 at 10:50
|
show 12 more comments
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55360628%2fcreate-async-validator-in-flutter%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I'm new to Fluuter (3 days so be indulgent) but I think you need to update
_isValid
inside thesetstate()
method. This method will rebuild the widget and modifiy the view.– Maxouille
Mar 26 at 15:21
@Maxouille appreciate your honesty :D but
setState()
I also tried and it didn't work neither.– supersize
Mar 26 at 15:22
1
Okay srry. Interested in the answer so :)
– Maxouille
Mar 26 at 15:23
Have you tried awaiting your code when you validate the phone number? If not the code execution may just continue without having actually validated if the string is a phone number.
– R. Duggan
Mar 26 at 15:36
1
If you want to check input asynchronously then you can use stream and block to do so.
– Viren V Varasadiya
Mar 26 at 15:47