Example of Wrap Widget in Flutter Android iOS

Rows and columns are the base of every flutter application. But sometimes we run out of room then we face the layout overflowed error. This error comes when there is no extra space available in current row and the child widget cannot move further. To solve this error Wrap widget comes here, Wrap widget lay it’s children one at a time and when it ran out space in current row then it will move the next children to the next row automatically. So in this tutorial we would learn about Example of Wrap Widget in Flutter Android iOS.

Contents in this project Example of Wrap Widget in Flutter Android iOS:

1. Open your project’s main.dart file and import material.dart package.

2. Creating void main runApp() method and calling MyApp class here.

3. Creating our main MyApp extends StatelessWidget class. This is our main class.

5. Creating Widget Build Area -> MaterialApp -> Scaffold Widget -> SafeArea Widget -> Container Widget.

6. Creating Wrap widget and Put multiple Container widgets as its children to see the work of wrap widget.

Wrap Widget Properties:

  • alignment : Used to set how children should wrap in main axis. Properties are WrapAlignment.center, WrapAlignment.end, WrapAlignment.spaceAround, WrapAlignment.spaceBetween, WrapAlignment.spaceEvenly.
  • direction : Used to set direction like horizontal for Row and vertical for Column.
  • spacing : Used to set space between each item.
  • runSpacing : Used to set space between each row like line height.

7. Complete source code for main.dart file:

Screenshot:

Example of Wrap Widget in Flutter Android iOS

Leave a Reply

Your email address will not be published.