Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter vertical divider as tall as its parent

Hi Flutter community:)

Working on a flutter app and seeking help with UI widget.

I'm lost on how to set child's height according to a parent's height.

Need to create a vertical divider(or Container with custom height) and set it's height to maximum of its parent because the parent height(which is a column in my case) will change depending on inside widgets.

I've found ways of creating vertical divider but with a fixed height. Tried using BoxFit, BoxConstraints, FittedBox and few other ways and failed to set height of a parent.

The divider is placed inside a Container>Row>Column->Container and divider's height should be the height of a Column.

As in example of this image:

https://i.stack.imgur.com/uUWjF.png

p.s. all widget is placed inside a ListView

      Column(
         children: <Widget>[
            Container(
              color: Colors.blue,
              width: 5.0,
              //height: -> setting to maximum of its parent
            ),
          ],
        ),
like image 394
petras J Avatar asked Aug 31 '18 10:08

petras J


People also ask

How do you change the height of the vertical divider in flutter?

The divider is placed inside a Container>Row>Column->Container and divider's height should be the height of a Column.

How do you insert a vertical divider in flutter?

You need to wrap VerticalDivider() widget with the IntrinsicHeight widget. Otherwise, the vertical divider will not show up. And to gain some padding over the top and bottom you can add indent.

How do you adjust the width of a divider flutter?

“divider width flutter” Code Answer's indent: 20, // empty space to the leading edge of divider. endIndent: 20, // empty space to the trailing edge of the divider. color: Colors. black, // The color to use when painting the line.

How do you remove a divider padding flutter?

So, setting height of divider to 0 will remove the padding.

How to use divider and verticaldivider in flutter?

In Flutter, there are two widgets suitable for that purpose: Divider and VerticalDivider. Divider is used to create a horizontal line divider, while VerticalDivider is used to create a vertical line divider. The examples below show you how to use those widgets. To use the Divider widget, just call the constructor. Below is the constructor.

What is the difference between divider and verticaldivider?

Divider is used to create a horizontal line divider, while VerticalDivider is used to create a vertical line divider. The examples below show you how to use those widgets. To use the Divider widget, just call the constructor.

How to use verticaldivider in widget?

Check out the docs but it's very simple to use — simply put it between two other items in a row. Note: If you are using VerticalDivider as separator in Row widget then wrap Row with IntrinsicHeight , Container or SizedBox else VerticalDivider will not show up. For Container and SizedBox widget you need define height.

What does double height mean on a divider?

double height: Height of the divider. double thickness: Thickness of the line. double indent: Empty space to the leading edge of the divider. double endIndent: Empty space to the trailing edge of the divider. Color color: Color of the line.


1 Answers

You can use IntrinsicHeight for this.

I used Container for my divider in this example, because I needed border radius on my divider, but you can use VerticalDivider too.

IntrinsicHeight(
        child: Row(
          children: <Widget>[
            // This is your divider
            Container(
              width: 3,
              height: double.infinity,
              color: Colors.blue,
              margin: const EdgeInsets.only(right: 4),
            ),
            Column(
              children: <Widget>[
                Text(
                  'Text 1',
                  style: TextStyle(fontSize: 20),
                ),
                Text(
                  'Text 2',
                  style: TextStyle(fontSize: 20),
                ),
                Text(
                  'Text 3',
                  style: TextStyle(fontSize: 20),
                ),
              ],
            ),
          ],
        ),
      ),

This is the result

If you just need a simple divider on the side I would suggest that you add border to the Container, because documetnation for IntrinsicHeight says is expensive to call, so avoid using it where possible.

Here you can read more about adding border to the Container.

like image 184
merfire Avatar answered Oct 10 '22 14:10

merfire