【发布时间】:2022-12-02 02:10:07
【问题描述】:
I am using extension to give padding to the widget
Extension:
extension Hello on Widget {
paddingAll(int x) {
return Container(
padding: const EdgeInsets.all(x.toDouble()),
child: this,
);
}
Use Case :
Container( child: Text("Hello")).paddingAll(40);
But this evaluates to :
return Container(
padding: const EdgeInsets.all(20),
child: Container(
child: Text("Hello"),
));
What I want is :
return Container(
padding: const EdgeInsets.all(20),
child: Text("Hello"),
);
How to achieve this via extension function? If any further more simplified method ,please suggest the same .
【问题讨论】:
-
what problem facing now?
-
I want to write an extension which evaluates to
what i want iscode. What i have now is the above one -
you can simply check over it inside the extension method, if(this == Container)...
标签: flutter widget extension-methods