import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Column and Row Demo')),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// Column with vertical Text widgets
const Text('Hello'),
const SizedBox(height: 8),
const Text('Flutter'),
const SizedBox(height: 8),
const Text('World'),
const SizedBox(height: 24),
// Row with horizontal Text widgets
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Text('Hello'),
SizedBox(width: 16),
Text('Flutter'),
SizedBox(width: 16),
Text('World'),
],
),
],
),
),
),
);
}
}We use a Column widget to stack the three Text widgets vertically. We add SizedBox widgets with fixed height to create space between them.
Below the Column, we add a Row widget with the same three Text widgets arranged horizontally. We add SizedBox widgets with fixed width to space them apart.
Both Column and Row are centered horizontally using crossAxisAlignment and mainAxisAlignment properties, and the whole layout is centered on screen with a Center widget.