I create generic Row to handle almost 90 percent of the basic feature.
I need your feedback to make it more flexible and extensible
/// A generic Row widget that allows customization of alignment, spacing, and padding.
///
/// - [children]: The list of widgets to display in the row.
/// - [mainAxisAlignment]: How the children should be aligned horizontally.
/// - [crossAxisAlignment]: How the children should be aligned vertically.
/// - [spacing]: The amount of space to add between children.
/// - [padding]: The padding to apply around the row.
/// - [useExpanded]: Whether to wrap children in Expanded to share space equally.
/// - [flexValues]: Optional flex values for each child when [useExpanded] is true.
///
/// Edge Cases and Limitations:
/// No Support for Flexible Ratios
/// If children is empty, the widget will still render an empty Row
/// It doesn't support multi sizes and multi ratio at the moment..
class GenericRow extends StatelessWidget {
final List<Widget> children;
final MainAxisAlignment mainAxisAlignment;
final CrossAxisAlignment crossAxisAlignment;
final double spacing;
final EdgeInsets padding; // Padding around the row
final bool useExpanded; // if set width will no effect on it
const GenericRow({
super.key,
required this.children,
this.mainAxisAlignment = MainAxisAlignment.center,
this.crossAxisAlignment = CrossAxisAlignment.center,
this.spacing = 0.0,
this.padding = EdgeInsets.zero,
this.useExpanded = true,
});
@override
Widget build(BuildContext context) {
return Padding(
padding: padding,
child: Row(
mainAxisAlignment: mainAxisAlignment,
crossAxisAlignment: crossAxisAlignment,
children: [
for (int index = 0; index < children.length; index++) ...[
if (useExpanded) Expanded(child: children[index]) else children[index],
if (index < children.length - 1) SizedBox(width: spacing),
],
],
),
);
}
}
I also added not possible items in comments.