Typed Accessors
Part of the API Reference. The PenvTypedAccess extension on Map<String, String> — available on whatever penvload returns, no separate import needed. These save the common int.parse(env['PORT']!) boilerplate at call sites, with clear errors when a value is missing or malformed.
final env = penvload('.env');
final port = env.getInt('PORT', defaultValue: 8080);
final debug = env.getBool('DEBUG', defaultValue: false);
final apiKey = env.getString('API_KEY'); // throws if missing/blank
getInt
int getInt(String key, {int? defaultValue}) {
Returns the value for key parsed as an int. Throws a FormatException if key is missing/blank and no defaultValue is given, or if the value isn’t a valid integer.
getDouble
double getDouble(String key, {double? defaultValue}) {
Returns the value for key parsed as a double. Throws a FormatException if key is missing/blank and no defaultValue is given, or if the value isn’t a valid double.
getBool
bool getBool(String key, {bool? defaultValue}) {
Returns the value for key parsed as a bool. Accepts (case-insensitively) true/false, 1/0, yes/no, and on/off. Throws a FormatException if key is missing/blank and no defaultValue is given, or if the value isn’t one of the above.
getString
String getString(String key, {String? defaultValue}) {
Returns the value for key, or defaultValue if key is missing or blank. Throws a FormatException if both are unavailable. This mirrors Map’s [] operator but gives a clear, actionable error instead of a null-check crash when a value is required.