Flutter - ConstrainedBox Widget Last Updated : 26 Sep, 2022 Comments Improve Suggest changes Like Article Like Report ConstrainedBox is a built-in widget in flutter SDK. Its function is to add size constraints to its child widgets. It comes quite handy if we want a container or image to not exceed a certain height and width. It is also good to keep text in a wrapped layout by making the Text widget a child on ConstrainedBox. This functionality can also be found in SizedBox widget or else. Constructor of ConstrainedBox Class:ConstrainedBox( {Key key, @required BoxConstraints constraints, Widget child} )Property of ConstrainedBox Widget:constraints: This property takes in the BoxConstrain Class as the object. It puts constraints it's child widget using the functions of the BoxConstraints class. Example 1: Dart import 'package:flutter/material.dart'; //imported googles material design library void main() { runApp( /**Our App Widget Tree Starts Here**/ MaterialApp( home: Scaffold( appBar: AppBar( title: Text('GeeksforGeeks'), backgroundColor: Colors.greenAccent[400], centerTitle: true, ), //AppBar body: Center( /** ConstrainedBox Widget **/ child: ConstrainedBox( constraints: BoxConstraints.expand(height: 200, width: 200), child: Container( color: Colors.green, ), //Container widget ), //ConstrainedBox ), //Center ), //Scaffold ), //MaterialApp ); } Output: Explanation: In this flutter application we can see that the ConstrainedBox Widget is used to constrain the height and width of its child widget which is a Container. Here we have used BoxConstraints.expanded with the height and width parameter set to 200. We can notice that the height and width parameters are not mentioned in the Container widget it just expands to fill its parent widget. Example 2: Dart import 'package:flutter/material.dart'; //imported googles material design library void main() { runApp( /**Our App Widget Tree Starts Here**/ MaterialApp( home: Scaffold( appBar: AppBar( title: Text('GeeksforGeeks'), backgroundColor: Colors.greenAccent[400], centerTitle: true, ), //AppBar body: Center( /** ConstrainedBox Widget **/ child: ConstrainedBox( constraints: BoxConstraints.expand(height: 200, width: 200), child: Text( 'A Computer Science portal for geeks. It contains well written,well thought and well explained computer science and programmingarticles, quizzes, interview experiences and much more.', style: TextStyle(fontSize: 15), ), //Text ), //ConstrainedBox ), //Center ), //Scaffold ), //MaterialApp ); } Output: Explanation: In this flutter app the ConstrainedBox widget is used to wrap the text in a 200 X 200 box. Here also the text expands to fill the box as BoxConstraints.expand is used. This application of ConstrainedBox widget is very helpful when we want our text to not spill out of a certain bounded area. Comment More infoAdvertise with us Next Article Flutter - ConstrainedBox Widget A ankit_kumar_ Follow Improve Article Tags : Dart Flutter Flutter-Widgets Similar Reads Flutter - BoxConstraints Widget BoxConstraints is a built-in widget in flutter SDK. Its functionality is to add sized constraints on its child widget. It is usually taken as the object of constraints property in ConstrainedBox widget. It comes packed with many properties for customization. Below we will see all its properties with 5 min read Flutter - ColoredBox Class Widget A Colored Box is a container that fills it with color according to its child or A widget that paints its area with a specified Color and then draws its child on top of that color. A sample image is given below to get an idea about what we are going to do in this article. Â How to use it? You can simp 3 min read Flutter - Checkbox Widget Checkbox in Flutter is a material design widget. It is always used in the Stateful Widget as it does not maintain its own state. We can use its onChanged property to interact with or modify other widgets in the Flutter app. Like most of the other flutter widgets, it also comes with many properties l 4 min read Flutter - AnimatedContainer Widget In Flutter a container is a simple widget with well-defined properties like height, width, and color, etc. The AnimatedContainer widget is a simple container widget with animations. These types of widgets can be animated by altering the values of their properties which are the same as the Container 3 min read Flutter - Custom Widgets We create Custom Widgets when we want a custom look and feel to our app, and we know that there will be a repetition of a particular widget. We can create the custom widget in a new dart file with all the codes and defining the parameters that we need in the constructor. For more on how to split wid 8 min read Like