为什么带级联的 dart 方法链不能与 setter 方法一起使用?

Cri*_*ano 0 dart

我有一些像这样的模型类:

class Environment {
  String _oidClientId;
  String _oidIssuerUrl;
  get issuerUrl => _oidIssuerUrl;
  set issuerUrl(String pIssuerUrl) => this._oidIssuerUrl = pIssuerUrl;
  get clientId => _oidClientId;
  set clientId(String pClientID) => this._oidClientId = pClientID;

}
Run Code Online (Sandbox Code Playgroud)

我尝试创建一个实例并使用级联在其上设置值:

var env = Environment.dev()
  ..clientId("my.id.public")
  ..issuerUrl("https://demo.myserver.com")

Run Code Online (Sandbox Code Playgroud)

但编译器给了我这个错误:

Undefined name 'clientId'.
Try correcting the name to one that is defined, or defining the name.dart(undefined_identifier)
Run Code Online (Sandbox Code Playgroud)

如果我更改代码,重命名 getter(由于名称重复)并将 setter 变成 avoid clientId(String pClientID)那么编译器不会抱怨。但我宁愿不这样做。我错过了什么吗?

Ale*_*uin 5

你滥用了二传手。以下代码应该可以工作:

var env = Environment.dev()
  ..clientId = "my.id.public"
  ..issuerUrl = "https://demo.myserver.com";
Run Code Online (Sandbox Code Playgroud)