The `int.fromEnvironment` constructor in Dart returns the integer value of the given environment declaration name.
The syntax of int.int.fromEnvironment constructor is:
int.fromEnvironment(String name, { int defaultValue })
This int.fromEnvironment constructor of int returns the integer value of the given environment declaration name.
Parameter | Optional/Required | Description |
---|---|---|
name | required | The name of the environment declaration. |
defaultValue | optional | The default value to return if the environment declaration is not found. |
In this example,
'MY_NUMBER'
to the string variable envName
.int.fromEnvironment()
with a default value of 42.void main() {
String envName = 'MY_NUMBER';
int myNumber = int.fromEnvironment(envName, defaultValue: 42);
print('Value of $envName: $myNumber');
}
Value of MY_NUMBER: 42
In this Dart tutorial, we learned about int.fromEnvironment constructor of int: the syntax and few working examples with output and detailed explanation for each example.