Space Between Widgets
Part of the Your First App section of Coddy's Flutter journey. Lesson 21 of 32.
The children of a Column touch each other. To add space between two of them, put an empty SizedBox in the list:
Column(
children: [
Text('Top'),
SizedBox(height: 20),
Text('Bottom'),
],
)A SizedBox draws nothing. It only takes up space: 20 pixels of height here. In a Row, use SizedBox(width: 20) instead.
Challenge
EasyPut 24 pixels of space between Title and Subtitle.
Try it yourself
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(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Title', style: TextStyle(fontSize: 32)),
Text('Subtitle'),
],
),
),
),
);
}
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Your First App
5Rows and Columns
ColumnRowSpace Between WidgetsCenter a ColumnLine Up the Left EdgesRows Inside ColumnsPractice on your own: Online Flutter compiler