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
),
],
),
The divider is placed inside a Container>Row>Column->Container and divider's height should be the height of a Column.
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.
“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.
So, setting height of divider to 0 will remove the padding.
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.
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.
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.
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.
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
Here you can read more about adding border to the Container.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With