Flutter Check TextField Text Input is Empty or Not iOS Android Example

In mobile applications sometimes user did not fill all available Text Input fields and we have to be sure that all the required values should be filled before submitting. We can do this by getting entered value from TextField and check whether the entered value is equal equal to empty or not and on certain task we can print Alert dialog box to notifying user that you have not filled all the TextField boxes. We are only printing a message on Terminal or Command Prompt screen but you can perform here any task according to your requirement. So in this tutorial we would Check TextField Text Input is Empty or Not in Flutter iOS Android Example Tutorial.

Contents in this project Check TextField Text Input is Empty or Not in Flutter iOS Android Example:

1. Import material.dart package in your app’s main.dart file.

2. Call our main MyApp class using void main runApp() method.

3. Create our main MyApp class extends with State less widget. We would call here CheckTextField() class directly.

4. Create a class named as CheckTextField extends with StatefulWidget. In this class we would pass the next class named as CheckTextFieldWidget with createState() method. This method would allow the mutable state management in given class tree.

5. Create a class named as CheckTextFieldWidget extends with State. In this class we would create all the TextField widget.

6. Create 3 final Text Controller  variables using TextEditingController() method. TextEditingController() is used to hold entered value for Text field widget.

7. Create a function named as checkTextFieldEmptyOrNot(). In this function first we would create 3 String variables and get value from TextField text controller. Now we would check whether the Text Input is empty or not using If condition.

8. Create 3 TextField widgets and 1 Button widget in Widget build area in CheckTextFieldWidget class. We are calling checkTextFieldEmptyOrNot() function on button onPress event.

9. Complete source code for main.dart file:

Screenshots:

Flutter Check TextField Text Input is Empty or Not iOS Android Example

Leave a Reply

Your email address will not be published.