Address constructor Null safety

Address(
  1. int _type,
  2. {String? accountId,
  3. String? contractId}
)

Constructs an Address for the given type which can be Address.TYPE_ACCOUNT or Address.TYPE_CONTRACT.

If Address.TYPE_ACCOUNT one must provide accountId. If Address.TYPE_CONTRACT one must provide contractId.

Implementation

Address(this._type, {this.accountId, this.contractId}) {
  if (this._type != TYPE_ACCOUNT && this._type != TYPE_CONTRACT) {
    throw new Exception("unknown type");
  }

  if (this._type == TYPE_ACCOUNT && this.accountId == null) {
    throw new Exception("invalid arguments");
  }

  if (this._type == TYPE_CONTRACT && this.contractId == null) {
    throw new Exception("invalid arguments");
  }
}