I have a custom class that extends Textstyle.
I want to change the background color property depending on parameter that I pass the class.
Suppose I pass parameter Yes for background color, it will show background color to Text, otherwise not.
Here is the code:
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(),
);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…