I'm tired of having to build a separate class to store color values. I hope to extend Colors and use Colors.aaa directly.
I wrote the following code:
extension colorExt on Colors {
static const Color cementTwo = const Color(0xff999990);
static Color aaa = Color(0xDD000000);
}
But it does not work. Can someone tell me why and how to correctly implement my needs
You can use like this,
extension colorExt on Color {
Color get newColor => Color(0xDD000000);
}
class MyWidget extends StatelessWidget {
Color color;
@override
Widget build(BuildContext context) {
return Container(
color: color.newColor,
width: 50,
height: 50
);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With