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
- 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.
The Error variable

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 .
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.
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 ]
You can follow @py_hat_.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: