Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Key Widgets
  • UI Components
  • Design & Animations
  • Forms & Gestures
  • Navigation & Routing
  • Flutter Interview Questions
  • Dart
  • Android
  • Kotlin
  • Kotlin Android
  • Android with Java
  • Android Studio
Open In App
Next Article:
RotatedBox Widget in Flutter
Next article icon

Flutter – SizedBox Widget

Last Updated : 17 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

SizedBox is a built-in widget in flutter SDK.  It is a simple box with a specified size. It can be used to set size constraints to the child widget, put an empty SizedBox between the two widgets to get some space in between, or something else. It is somewhat similar to a Container widget with fewer properties.

Constructor of SizedBox Class

 It draws a simple box with the mentioned height and width or a child widget inside. 

const SizedBox(
{
Key key,
double width,
double height,
Widget child}
)

Constructor of SizedBox.expand

 This implementation of the SizedBox widget allows it to be as big as the parent widget allows it to be. 

const SizedBox.expand(
{
Key key,
Widget child}
)

Constructor of SizedBox.fromSize

This allows the creation of a SizedBox with a specified size.

SizedBox.fromSize(
{
Key key,
Widget child,
Size size}
)

Constructor of SizedBox.shrink

 This implementation of the widget allows it to be as small as the child widget allows it to be. 

const SizedBox.shrink(
{
Key key,
Widget child}
)

Properties of SizedBox Widget

Property

Description

child

This property takes in a child widget as the object to display it below the SizedBox in the widget tree or inside the SizedBox on the screen.

height

This property specifies the height of the SizedBox in pixels. It is a double value as the object.

width

This property is also a double value as the object to give width to the SizedBox.


Example 1:

Dart
import 'package:flutter/material.dart';  //Importing material design library void main() {   runApp(     //Our app widget tree starts from here     MaterialApp(       debugShowCheckedModeBanner: false,       home: Scaffold(         appBar: AppBar(           title: Text('GeeksforGeeks'),           centerTitle: true,           backgroundColor: Colors.green,           foregroundColor: Colors.white,         ), //AppBar         body: Center(           //SizedBox Widget           child: SizedBox(             width: 200.0,             height: 100.0,             child: Card(               color: Colors.green,               child: Center(                 child: Text(                   'GeeksForGeeks',                   style: TextStyle(color: Colors.white, fontSize: 25),                 ), //Text               ), //Center             ), //Card           ), //SizedBox         ), //Center       ), //Scaffold     ), //MaterialApp   ); } 

Output:

sizedbox

Explanation of the above Program:

By taking a look at the code, We can see that the body of this flutter app is holding the Center widget as the parent of all. Inside the Center widget, we have a SizedBox whose height is mentioned as 100 pixels and width as 200 pixels. The SizedBox widget is holding the Card as the child and restricting its size.

Using SizedBox.expand

Dart
SizedBox.expand(     child: Card(       color: Colors.green,       child: Center(         child: Text(           'GeeksForGeeks',           style: TextStyle(color: Colors.white,           fontSize: 25           ),         ), //Text       ), //Center     ), //Card   ), //SizedBox.expand 

Output:

sizedboxexpand

Explanation of the above Program:

Here we have used the SizedBox.expand which is enabling it to expand as big as its parent allows. And the Center widget allows it to fill the whole screen.

Example 2:

Dart
Center(   child: Row(     children: <Widget>[       Container(         width: 200,         height: 200,         color: Colors.red,       ), //Container       //SizedBox Widget       SizedBox(         width: 50,       ),       Container(         width: 100,         height: 100,         color: Colors.blue,       ) //Container     ], //<Widget>[]   ), //Row ), //center 

Output: 

sizedboxspace

Explanation of the above Program:

In this example, we have used the SizedBox widget to add a gap between the two Container widgets. Here, we have two Container widgets inside the Row. The first red container has a height and width of 200 pixels each. The second blue has a height and width of 100 pixels each. And in between these two containers, we have a SizedBox widget with a width of 50 pixels and no height.



Next Article
RotatedBox Widget in Flutter
author
ankit_kumar_
Improve
Article Tags :
  • Flutter
  • Flutter
  • Flutter-Widgets

Similar Reads

  • RotatedBox Widget in Flutter
    The RotatedBox widget is used to rotate its child by an integral number of quarter turns. It is used to orient its child widgets into either horizontal or vertical orientation. Furthermore, it is very lightweight and can be used for designing various UI as it gives flexibility to the user over the D
    2 min read
  • Flutter - Positioned Widget
    Positioned is a widget that comes built-in with flutter SDK. Positioned does exactly what it sounds like, which is it arbitrarily positioned widgets on top of each other. It is usually used to position child widgets in Stack widget or similar. It only works for Stateless and Stateful widgets. Constr
    3 min read
  • Flutter - ListTile Widget
    The ListTile widget is used to populate a ListView in Flutter. It contains a title as well as leading or trailing icons. Let's understand this with the help of an example. The Constructor of the ListTile classListTile({ Key key, Widget leading, Widget title, Widget subtitle, Widget trailing, bool is
    4 min read
  • Flutter - RichText Widget
    The RichText widget is used to display text that uses various different styles. The displayed text is described using a tree of TextSpan objects, each of which has its own associated style that is used for that subtree. Depending on the layout constraints the text might break across multiple lines o
    3 min read
  • Flutter - SizeTransition Widget
    In this article, we will explore the Flutter SizeTransition Widget. The Size Transition Widget is a key tool in Flutter that lets you animate the size of a child widget. It can be used to make a widget appear or vanish, create a zoom-in or zoom-out effect, and for many more things. A sample video is
    7 min read
  • Flutter - Inherited Widget
    If you are a flutter developer then you know how easy is to create Flutter UI. But when you have lots of widgets in your app and you want to pass data from one widget to another widget, this will be a pain for many developers,s especially for the newbie, this will be really hard for them to pass the
    6 min read
  • Flutter - SliverAppBar Widget
    SliverAppBar is a Material Design widget in Flutter that gives a scrollable or collapsible app bar. The word Sliver is given to scrollable areas here. It allows us to create an app bar that can change appearance, blend in the background, or even disappear as we scroll. We already had AppBar widget i
    5 min read
  • Flutter - TabView Widget
    There are lots of apps where you often have come across tabs. Tabs are a common pattern in the apps. They are situated at top of the app below the App bar. So today we are going to create our own app with tabs. Table of Contents:Project SetupCodeConclusionProject Setup: You can either create a new p
    4 min read
  • Flutter - InkWell Widget
    InkWell is the material widget in flutter. It responds to the touch action as performed by the user. Inkwell will respond when the user clicks the button. There are so many gestures like double-tap, long press, tap down, etc. Below are the so many properties of this widget. We can set the radius of
    2 min read
  • Flutter - Stepper Widget
    In this article, we will learn about the Stepper widget in Flutter. A stepper widget displays progress through a sequence of steps. Stepper is generally used in filling forms online. For example, remember filling an online form for applying to any university or passport or driving license. We filled
    8 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences