Flutter / layouts / Sizebox
Sizebox
-
Usage
SizedBox is a widget used to enforce a specific size for its child or to create empty space. It's particularly useful when you need to set explicit dimensions or add space between widgets.
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('SizedBox Example'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( color: Colors.blue, height: 100, width: 100, child: Center(child: Text('Box 1')), ), SizedBox(height: 20), // Adds 20 pixels of vertical space Container( color: Colors.green, height: 100, width: 100, child: Center(child: Text('Box 2')), ), SizedBox(width: 20), // Adds 20 pixels of horizontal space Container( color: Colors.orange, height: 100, width: 100, child: Center(child: Text('Box 3')), ), SizedBox( width: 200, height: 50, child: ElevatedButton( onPressed: () {}, child: Text('Button'), ), ), ], ), ), ), ); } }