VOOZH about

URL: https://www.geeksforgeeks.org/dart/wrap-widget-in-flutter/

⇱ Flutter - Wrap Widget - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Flutter - Wrap Widget

Last Updated : 27 May, 2021

Wrap widget aligns the widgets in a horizontal and vertical manner. Generally, we use Rows and Columns to do that but if we have some widgets which are not able to fit in the Row/Column then it will give us Overflow Message ( for ex: Right Overflowed by 570 pixels). 

Constructor of Wrap class:

Wrap({Key key, 
Axis direction, 
WrapAlignment alignment, 
double spacing, 
WrapAlignment runAlignment, 
double runSpacing, 
WrapCrossAlignment crossAxisAlignment, 
TextDirection textDirection, 
VerticalDirection verticalDirection, 
List<Widget> children})

Properties:

  • direction: By default, the axis is horizontal but we can make it vertical by changing the axis from Axis.horizontal to Axis.vertical.
  • alignment: We can set the alignment property to align widgets. (for ex : alignment : WrapAlignment.center).
  • spacing: We can give space between the children.
  • runAlignment: It shows how runs themselves should be placed in the cross axis. By default, we have runAlignment as WrapAlignment.start.
  • runSpacing: We can give runSpacing between the runs. (ex: runSpacing:5.0).
  • crossAxisAlignment: We can align the children relative to each other in cross Axis.
  • textDirection : We can arrange children in a row using textDirection (for ex : textDirection: TextDirection.rtl to arrange from right to left).
  • clipBehaviour: This property takes in Clip enum as the object to decide whether the content inside the Wrap widget will be clipped or not.
  • children: The childrenproperty takes in a list of widgets as the object to show inside the Wrap widget or below the Wrap widget in the widget tree.
  • verticalDirection: This property takes in VerticalDirection enum as the object to. This property decides the order in which each children widget will be painted on the screen in a vertical sense.
  • runtimeType: Type class is the object given to the runtimeType property. It determines the type of the Wrap widget at the run time.
  • key: This property decides how one widget will replace another widget on the screen.
  • haskCode: This property takes in an int value as the object which represents the state of the widget.

Implementation with Example:

main.dart

Explanation:

direction: Axis.horizontal // default

Output: 

👁 wrap wiggets
direction: Axis.vertical

Output: 

👁 wrap wiggets
alignment: WrapAlignment.center

Output: 

👁 wrap wiggets
alignment: WrapAlignment.center,
spacing:8.0,

Output: 

👁 wrap wiggets
alignment: WrapAlignment.center,
spacing:8.0,
runSpacing: 8.0,

Output: 

👁 wrap wiggets
spacing:8.0,
runSpacing: 8.0,
textDirection: TextDirection.rtl,

Output:

👁 wrap wiggets
spacing:8.0,
runSpacing: 8.0,
verticalDirection: VerticalDirection.up,

Output:

👁 wrap wiggets
Comment
Article Tags:
Article Tags:

Explore