Flutter : Showing errorText programmatically in a StatefullWidget
A thread
http://developerm.dev/2020/11/08/flutter-showing-errortext-programmatically-in-a-statefullwidget/
A thread

Flutter let us display error message based on the wrong input. This is possible with InputDecoration ( https://developerm.dev/2020/11/06/make-the-ui-interactive-with-inputdecoration-widget-in-flutter/). Using the widget we can pass Error message as follows.
How to display Error programmatically
In StatefullWidget we can use setState method to update the UI. We can do update UI based on the error we found by doing the following
In StatefullWidget we can use setState method to update the UI. We can do update UI based on the error we found by doing the following
- Create variable in your State class, say bool dateError
- Use the variable in the errorText of the InputDecoration
- Update the variable in a event like Onpressed or OnTap of a widget.
- Use the variable in the errorText of the InputDecoration
- Update the variable in a event like Onpressed or OnTap of a widget.
The Error variable
The Error variable can be declared in the State portion of the widget as follows
The Error variable can be declared in the State portion of the widget as follows
Checking the Error on errorText
We can check on the variable for showing errorText message using the conditional operator and the dateError variable .
We can check on the variable for showing errorText message using the conditional operator and the dateError variable .
Every time we a change the errorDate variable to true the message will appear. How do we change it? The Flutter Statefull widget can only detect change in a variable by using state, so it can update the UI.
Updating the dateError
Using an event listener and setState () we can update the dateError. The UI only detect change while it is done with setState ().
Here txtDate is a TextFieldEditingcontroller used to capture ( https://developerm.dev/2020/11/03/accessing-value-from-a-text-field-in-flutter/) the input value from TextField.
Using an event listener and setState () we can update the dateError. The UI only detect change while it is done with setState ().
Here txtDate is a TextFieldEditingcontroller used to capture ( https://developerm.dev/2020/11/03/accessing-value-from-a-text-field-in-flutter/) the input value from TextField.
As you can see the UI only show errorText while the dateError set to true .
The following list of posts may help you.
[display-posts category=Flutter ]
The following list of posts may help you.
[display-posts category=Flutter ]
This thread can be read here: http://developerm.dev/2020/11/08/flutter-showing-errortext-programmatically-in-a-statefullwidget/