W3cubDocs

/Dart 2

int.fromEnvironment constructor

const int.fromEnvironment(String name, { int defaultValue })

Returns the integer value of the given environment declaration name.

The result is the same as would be returned by:

int.tryParse(const String.fromEnvironment(name, defaultValue: ""))
    ?? defaultValue

Example:

const int.fromEnvironment("defaultPort", defaultValue: 80)

Implementation

// The .fromEnvironment() constructors are special in that we do not want
// users to call them using "new". We prohibit that by giving them bodies
// that throw, even though const constructors are not allowed to have bodies.
// Disable those static errors.
//ignore: const_constructor_with_body
//ignore: const_factory
external const factory int.fromEnvironment(String name, {int defaultValue});

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.5.0/dart-core/int/int.fromEnvironment.html