EnvConfig.fromJson constructor
EnvConfig.fromJson(
- Map<String, dynamic> jsonValue
)
Implementation
factory EnvConfig.fromJson(final Map<String, dynamic> jsonValue)
{
final jsonHost = jsonValue['host'] ?? _host;
if (jsonHost is! String) {
throw const ConfigException('host is expected to be a valid string.');
}
final jsonPort = jsonValue['port'] ?? _port;
if (jsonPort is! int) {
throw const ConfigException('port is expected to be a valid number.');
}
final jsonUser = jsonValue['user'] ?? _user;
if (jsonUser is! String) {
throw const ConfigException('user is expected to be a valid string.');
}
final jsonDbName = jsonValue['dbName'] ?? _dbName;
if (jsonDbName is! String) {
throw const ConfigException('dbName is expected to be a valid string.');
}
final jsonTableName = jsonValue['tableName'] ?? _tableName;
if (jsonTableName is! String) {
throw const ConfigException('tableName is expected to be a valid string.');
}
final jsonHomeDbName = jsonValue['homeDbName'] ?? jsonUser;
if (jsonHomeDbName is! String) {
throw const ConfigException('homeDbName is expected to be a valid string.');
}
return EnvConfig(
host: jsonHost,
port: jsonPort,
user: jsonUser,
dbName: jsonDbName,
tableName: jsonTableName,
homeDbName: jsonHomeDbName,
);
}