I found out intersting way of reducing the work required for customizing widgets via extension
Ex: To make the text red i would make an extension like the following
Container(
child: "Krishna".redText(),
)
extension TextTheme on String {
redText() {
return Text(
this,
style: const TextStyle(color: Colors.red),
);
}
}
I want to extend this further by using the chain method . But unfortunately I can't find much resources using this method .
Example to make the text further bold , I want to define bold()
extension Theme on Text {
bold() {
return Text(
data!,
style: const TextStyle(fontWeight: FontWeight.bold),
);
}
}
And use as "Krishna".redText().bold()
It gives me error
NoSuchMethodError: Class 'Text' has no instance method 'bold'.
Receiver : Instance of 'Text'
Tried calling : bold()
I am looking forward for a solution and more examples to achieve the same or good method of achieving this property using extension.