I wrote an extension function to add SizedBox between every child in Column or Row to add space between child, instead of putting SizedBox between every child, for which I didn't find any other way around.
Column(
children: [
// widgets
].setSpace(height: 10),
)
Row(
children: [
// widgets
].setSpace(width: 10),
)
So here List<Widget> setSpace({double? height, double? width}) takes height or width for the SizedBox used between child. But since height and width are not const I cannot use const SizedBox. So is there any way in dart to say that both the parameters and the return type will ALWAYS be cosnt? like const List<Widget> setSpace({const double? height, const double? width}) like C/C++?
I don't think that's possible, mostly because
constcan be applied only on constructors and fields, not on generic functions. Maybe you can achieve that by creating your own widget that adds theSizedBoxin itsbuildmethod, and create aconstconstructor.EDIT: here's a piece of code of mine of a custom widget with a
constconstructor.EDIT 2: here's a piece of code tested in DartPad. I don't think it can get better than this.