我想扩展具有以下构造函数的 Text 类:
const Text(this.data, {
Key key,
this.style,
this.textAlign,
this.softWrap,
this.overflow,
this.textScaleFactor,
this.maxLines,
}) : assert(data != null),
super(key: key);
Run Code Online (Sandbox Code Playgroud)
但是我对 super 的可选参数和语法有疑问。所以,我想做的是:
BlinkingText(data,
{key,
style,
textAlign,
softWrap,
overflow,
textScaleFactor,
maxLines}):
super(data, {key, style, textAlign, softWrap, overflow, textScaleFactor, maxLines});
Run Code Online (Sandbox Code Playgroud)
但是语法是错误的。所以我想知道我应该如何处理可选参数,以及是否有一种简单的方法来获取一堆参数并在我将它们传递给 super 时传递它们。
将所有参数传递给超类没有简写。
您可以通过在名称前加上命名参数来传递命名参数,因此:
BlinkingText(data,
{key,
style,
textAlign,
softWrap,
overflow,
textScaleFactor,
maxLines})
: super(data, key: key, style: style, textAlign: textAlign,
softWrap: softWrap, overflow:overflow,
textScaleFactor: textScaleFactor, maxLines: maxLines);
Run Code Online (Sandbox Code Playgroud)
这与在非构造函数中使用命名参数的方式相同。
| 归档时间: |
|
| 查看次数: |
2640 次 |
| 最近记录: |