Padding
Part of the Your First App section of Coddy's Flutter journey. Lesson 17 of 32.
A box that hugs its text looks cramped. padding: adds space inside the box, between its edge and its child:
Container(
padding: EdgeInsets.all(16),
color: Colors.yellow,
child: Text('Room to breathe'),
)EdgeInsets.all(16) means 16 pixels on all four sides. EdgeInsets.symmetric(horizontal: 24, vertical: 8) sets the sides and the top and bottom apart.
A Container also has margin:. That is space outside the box, between it and its neighbors. The colored part does not grow.
Challenge
EasyGive Fresh some room: add 24 pixels of padding on every side, inside the green box.
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: Container(
color: Colors.lightGreen,
child: Text('Fresh', style: TextStyle(fontSize: 32)),
),
),
),
);
}
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Your First App
Practice on your own: Online Flutter compiler