Your experience on this site will be improved by allowing cookies
When we create any child of a row or column we provide the size of the widget according to the screen size but sometimes when we provide more size of child as compared to screen size we get a warning and our widget goes out of the screen for resolving this we put a child of a row or column in an expanded widget so that the child occupies only the available space along the main axis. When we create multiple children then the available space between the children will divide according to the flex factor. An expanded widget contains only the stateful widget or stateless widget not other kinds of widgets like RenderObjectWidgets.
Syntax: Expanded( { Key key, int flex: 1, @required Widget child, } )
Example:
|
Output:
In the below image the image of dice goes out of the screen because the required size for the image is more than the screen size.
Without using Expanded class
We have used the Expanded class to make our image more flexible so that it can fit the screen size.
Image after using Expanded class
By using the Expanded class our image has fitted to available space only.
Example: For Inserting Multiple images
|
Output:
In this, we have inserted the multiple-image of dice. By default, the flex size is 1, but we can change it to our requirement.
Multiple Images
This Flex factor is set to 2 and image 1 is twice the size of image two.
0 comments