withSpacing method
Implementation
Row withSpacing(double spacing) {
if (children.isEmpty) return this;
// 在每两个子 Widget 之间插入 SizedBox
final List<Widget> spacedChildren = [];
for (int i = 0; i < children.length; i++) {
spacedChildren.add(children[i]);
if (i < children.length - 1) {
spacedChildren.add(SizedBox(width: spacing));
}
}
return Row(
mainAxisAlignment: mainAxisAlignment,
crossAxisAlignment: crossAxisAlignment,
mainAxisSize: mainAxisSize,
children: spacedChildren,
);
}