In Flutter, the Row widget is another layout widget, similar to Column, but it arranges its children in a horizontal sequence (from left to right). Each child of a Row widget is drawn in the order in which it appears in the children list.
Now, let's go over some common attributes of the Row widget:
children: A list of widgets to be displayed in the row, arranged in the order they appear in the list.
Row( children: [ Text('First Child'), Text('Second Child'), // More children... ], )
mainAxisAlignment: Defines how the children should be placed along the main axis (horizontally, in the case of a Row). Possible values are the same as for Column:
start: Align children at the start of the main axis.
end: Align children at the end of the main axis.
center: Center children along the main axis.
spaceBetween: Space children evenly along the main axis with space between them.
spaceAround: Space children evenly along the main axis with space around them.
spaceEvenly: Space children evenly along the main axis with equal space on both ends.
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Centered Child'),
// More children...
],
)
crossAxisAlignment: Defines how the children should be placed along the cross axis (vertically, in the case of a Row). Possible values are the same as for Column:
start: Align children at the top of the cross axis.
end: Align children at the bottom of the cross axis.
center: Center children along the cross axis.
stretch: Stretch children to fill the cross axis.
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('Centered Child'),
// More children...
],
)
mainAxisSize: Defines the size of the row along its main axis. Possible values are the same as for Column: MainAxisSize.min (shrinks to fit its children) and MainAxisSize.max (takes up as much space as possible along the main axis).
Row( mainAxisSize: MainAxisSize.max, children: [ // Children... ], )
textDirection: Defines the order in which the children are placed along the main axis. Possible values include TextDirection.ltr (left to right) and TextDirection.rtl (right to left).
Row( textDirection: TextDirection.ltr, children: [ // Children... ], )
These attributes allow you to control the layout and appearance of a Row widget, just like with the Column widget. You can customize them according to your UI design requirements.
Here's a basic example of a Row
widget:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Row Widget Example'),
),
body: Row(
children: [
Text('First Child'),
Text('Second Child'),
Text('Third Child'),
],
),
),
);
}
}