by @kodeazy
flutter how to check String is numeric in dart file?
- To convert String to Integer in dart file we use
int.parse()
method. - To check whether given string can be converted into Integer we use
try-on
block. -
If the given string is not numeric statement inside
on
block is executed.
void main() { String number = “10”; int convertedNumber; try { convertedNumber = int.parse(number); } on FormatException { print(“Given String Is Not Numeric”); return; } print(convertedNumber); print(“Given String Is Numeric”); }
Output:
```js
10
Given String Is Numeric