我想延长Text class which has following constructor:
const Text(this.data, {
Key key,
this.style,
this.textAlign,
this.softWrap,
this.overflow,
this.textScaleFactor,
this.maxLines,
}) : assert(data != null),
super(key: key);
但我有super的可选参数和语法问题。所以,我想要做的是:
BlinkingText(data,
{key,
style,
textAlign,
softWrap,
overflow,
textScaleFactor,
maxLines}):
super(data, {key, style, textAlign, softWrap, overflow, textScaleFactor, maxLines});
但语法错了。所以我想知道我应该如何处理可选参数,以及是否有一种简单的方法来获取参数的束并在我将它们传递给super时传递它们。
答案 0 :(得分:3)
没有简写将所有参数传递给超类。
通过在命名参数前面添加名称来传递命名参数,因此:
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);
这与使用非构造函数的命名参数的方式相同。