get<T> static method

T get<T>(
  1. String key, [
  2. dynamic defaultValue
])

get env value

Evn.get('APP_KEY');
Evn.get('APP_KEY', 'Default Value');
Evn.get<int>('PORT', 3000);
Evn.get<num>('PORT', 3000);
Evn.get<String>('APP_KEY');

Implementation

static T get<T>(String key, [dynamic defaultValue]) {
  dynamic value = Env().env[key];
  value ??= Platform.environment[key];
  value ??= defaultValue;
  if (T.toString() == 'int') {
    return int.parse(value.toString()) as T;
  }
  if (T.toString() == 'num') {
    return num.parse(value.toString()) as T;
  }

  if (T.toString() == 'bool') {
    return bool.parse(value.toString()) as T;
  }

  return value;
}