This app shows three widgets stacked vertically:
- A text above a space.
- A text with padding around it.
- A button inside a fixed size box.
The SizedBox adds vertical space and fixes button size. The Padding adds space inside the text widget.
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('SizedBox and Padding Example')),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text('Above SizedBox'),
const SizedBox(height: 30),
const Padding(
padding: EdgeInsets.all(20),
child: Text('Text with Padding'),
),
const SizedBox(height: 30),
SizedBox(
width: 150,
height: 50,
child: ElevatedButton(
onPressed: () {},
child: const Text('SizedBox Button'),
),
),
],
),
),
),
);
}
}