我想创建一个继承的AppBar
叫HomeAppBar
,它继承自CommonAppBar
,它继承自AppBar
. CommonAppBar
将背景设置为紫色并将HomeAppBar
标题设置为Hourlogger
class CommonAppBar extends AppBar {
CommonAppBar() : super(backgroundColor: Colors.purple);
}
class HomeAppBar extends CommonAppBar {
HomeAppBar() : super(title: Text("Hourlogger"));
}
但是编译器说
未定义命名参数“title”。尝试将名称更正为现有命名参数的名称,或使用名称“title”定义命名参数。
我的印象是CommonAppBar
应该title
从AppBar
. 我应该如何title
在我的自定义中设置AppBar
?
class CommonAppBar extends AppBar {
final Widget title;
CommonAppBar({this.title}) : super(backgroundColor: Colors.purple, title: title);
}
class HomeAppBar extends CommonAppBar {
HomeAppBar() : super(title: Text("Hourlogger"));
}
这应该适用于您首先从构造函数中获取 title 参数并将其传递给 super
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句