Flutter Dart Check Entered String Value is Number or Not Example

In dart there is a inbuilt function named as _isNumeric() which is Boolean type return value function. Using the _isNumeric(String) function we can easily check whether the entered value in TextField widget is numeric or not. The _isNumeric() function would return true if the value is numbered and return false if the entered string contains non numeric numbers. So in this tutorial we would Flutter Dart Check Entered String Value is Number or Not in Android iOS Example Tutorial in Text Input TextField widget.

Contents in this project Flutter Dart Check Entered String Value is Number or Not Android iOS Example Tutorial:

1. Open your project’s main.dart file and import material.dart package inside it.

2. Creating void main runApp() method and here we would call our main MyApp class.

3. Creating our main Root parent class named as MyApp extends StatelessWidget. Inside this class we would call TextFieldClass as child.

4. Creating another class named as TextFieldClass extends StatefulWidget. In this class we would call the createState() method of State to enable mutable state in given class tree.

5. Creating another class named as TextFieldClassState extends State. This is our main View child class in which we would write all widgets code.

6. Creating a final textFieldHolder variable to use as TextEditingController(). To extract value from TextField widget we have to use TextEditingController.

7. Creating a variable named as value. We would store the Text Input entered value in value variable.

8. Creating a variable named as output with default message text Not Checked. We would use this variable to hold the result like Entered value is number or Entered value is Not number and display the message on mobile app screen.

9. Creating a function named as checkTextInputData(), Using this function we would first store the TextField entered value on value variable using State then we would call the _isNumeric() function with Value and after checking value is number or not we would set the result in output variable.

10. Creating our main value checking function named as _isNumeric() Boolean type.

Note: If the entered value is pure number then it will returns us True and if the entered value is not number then it will returns us False.

11. Creating Widget Build Area -> Column widget -> TextField widget, Raised Button widget and Text widget.

12. Complete source code for main.dart file:

Screenshots:

Flutter Dart Check Entered String Value is Number or Not Example Flutter Dart Check Entered String Value is Number or Not Example

Leave a Reply

Your email address will not be published. Required fields are marked *