我有一个扩展 Textstyle 的自定义类。我想根据传递给类的参数更改背景颜色属性。
假设我为背景颜色传递参数 Yes,它将向 Text 显示背景颜色,否则不会。
这是代码:
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
children: [
Text(
"aaaaaaaaaaaaaaa",
style: CtrBlblStyle(PARAMETER:"Y"),
)
],
),
),
);
}
}
class CtrPublic {
static const Color backgroundColor = Colors.green;
}
class CtrBlblStyle extends TextStyle {
final backgroundColor;
CtrBlblStyle({
**//if(parameter='Y'{
// this.backgroundColor = CtrPublic.backgroundColor,}
//endif**
// this.backgroundColor = CtrPublic.backgroundColor,
});
}
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(),
);
}
}