Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('One'),
Text('Two'),
Text('Three'),
],
)MainAxisAlignment.spaceBetween places the first child at the start and the last child at the end of the main axis. The remaining children are spaced evenly between them, so the gaps between children are equal but no extra space is added at the start or end.
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text('Hello'),
Text('World'),
],
)In a Column, the cross axis is horizontal. Setting CrossAxisAlignment.stretch passes tight horizontal constraints (Column's full width) to children. Text widgets size to their intrinsic width (content-based) rather than expanding to fill, and are positioned at the start (left-aligned).
class MyWidget extends StatefulWidget { @override State<MyWidget> createState() => _MyWidgetState(); } class _MyWidgetState extends State<MyWidget> { MainAxisAlignment alignment = MainAxisAlignment.start; void toggleAlignment() { setState(() { alignment = alignment == MainAxisAlignment.start ? MainAxisAlignment.center : MainAxisAlignment.start; }); } @override Widget build(BuildContext context) { return Column( children: [ Row( mainAxisAlignment: alignment, children: [Text('A'), Text('B'), Text('C')], ), ElevatedButton( onPressed: toggleAlignment, child: Text('Toggle Alignment'), ), ], ); } }
Calling setState causes Flutter to rebuild the widget tree under the StatefulWidget. The Row receives the new mainAxisAlignment value and updates its layout accordingly, so the UI changes immediately.
Row(
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
Text('Hello', style: TextStyle(fontSize: 20)),
Text('World', style: TextStyle(fontSize: 14)),
],
)When using CrossAxisAlignment.baseline, you must provide a textBaseline property with a valid value like TextBaseline.alphabetic. Omitting it or setting it to null causes a runtime error.
In a Row, the cross axis is vertical (height). CrossAxisAlignment.stretch requires the Row to have bounded height to pass finite height constraints to children. Without bounded height (e.g., Row in a Column), children get unbounded height and cannot stretch effectively.