我创建了扩展StatelessWidget的Blabel类。我想将其扩展到Blabel1,保留其所有属性并为其添加一些额外的属性。
假设我想将textDirection
属性添加到新类中。我该怎么做?
这是Blabel
我的班级代码:
class Blabel extends StatelessWidget {
final String text;
final TextStyle style;
Blabel({
this.text,
this.style,
});
@override
Widget build(BuildContext context) {
return Text(
text,
style: style ?? CtrBlblStyle(),
);
}
}
我认为这是您要寻找的东西:
class Blabel1 extends Blabel {
final TextDirection textDirection; // example of new property
Blabel1({
String text,
TextStyle style,
this.textDirection,
}) : super(text: text, style: style);
@override
Widget build(BuildContext context) {
// You can change the build method to change the UI from Blabe
return Text(
text,
style: style ?? CtrBlblStyle(),
);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句