23

Good day.

I've surfed on this website about how to add a Vertical Divider between Widget on Column in Flutter? but I got nothing.

here what I want enter image description here

I already make the horizontal divider. but when I try to make a vertical divider that separating between 2 objects (text | image), I got nothing.

here are the code:

Row(children: <Widget>[
                Expanded(
                  child: new Container(
                      margin: const EdgeInsets.only(left: 10.0, right: 20.0),
                      child: Divider(
                        color: Colors.black,
                        height: 36,
                      )),
                ),
                Text("OR"),
                Expanded(
                  child: new Container(
                      margin: const EdgeInsets.only(left: 20.0, right: 10.0),
                      child: Divider(
                        color: Colors.black,
                        height: 36,
                      )),
                ),
              ]),

code above is for horizontal

Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: <Widget>[
            Row(
              children: <Widget>[
                Image.asset('images/makanan.png', width: 30,),
                Text('Diskon 20%', style: TextStyle(fontSize: 5, color: Colors.green),)
              ],
            ),
            VerticalDivider(
              color: Colors.red,
              width: 20,
            ),
            Row(
              children: <Widget>[
                Image.asset('images/makanan.png', width: 30,),
                Text('Diskon 20%', style: TextStyle(fontSize: 5, color: Colors.green),)
              ],
            ),
          ],
        ),

code above I make for Vertical Divider. but failed.

Need your help, Thank you.

Krupa Kakkad
  • 857
  • 1
  • 13
  • 28
Roman Traversine
  • 868
  • 4
  • 12
  • 22

7 Answers7

69

Try to replace

VerticalDivider(color: Colors.red, width: 20)

with

Container(height: 80, child: VerticalDivider(color: Colors.red))
sunxs
  • 886
  • 8
  • 4
10

Try this:

IntrinsicHeight(
    child: new Row(
  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  children: <Widget>[
    Text('Foo'),
    VerticalDivider(),
    Text('Bar'),
    VerticalDivider(),
    Text('Baz'),
  ],
))
AnasSafi
  • 5,353
  • 1
  • 35
  • 38
  • 1
    This works but can be very costly, this widget can result in a layout that is O(N²) in the depth of the tree. – IgZiStO May 20 '20 at 16:34
  • This is the only way that do not need to specify height manually, so I think It's worth to try If there is no other solution. – Tokenyet Jul 27 '20 at 06:50
4

oke here the answer.

it works for me. Thank you mr @Android Team and mr @sunxs for your help :)

Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: <Widget>[
            Row(
              children: <Widget>[
                Image.asset('images/makanan.png', width: 30,),
                Text('Diskon 20%', style: TextStyle(fontSize: 5, color: Colors.green),)
              ],
            ),
            Container(height: 80, child: VerticalDivider(color: Colors.red)),
            Row(
              children: <Widget>[
                Image.asset('images/makanan.png', width: 30,),
                Text('Diskon 20%', style: TextStyle(fontSize: 5, color: Colors.green),)
              ],
            ),
            Container(height: 80, child: VerticalDivider(color: Colors.red)),
            Row(
              children: <Widget>[
                Image.asset('images/makanan.png', width: 30,),
                Text('Diskon 20%', style: TextStyle(fontSize: 5, color: Colors.green),)
              ],
            ),
          ],
        ),
Roman Traversine
  • 868
  • 4
  • 12
  • 22
4

you can either use

VerticalDivider(
thickness: 1,
color:Colors.black
            
),

or

Container(
height: 30,
width: 1,
color: Colors.black

)
F.K
  • 93
  • 7
2

The most optimal way is to put the Vertical Divider inside a SizedBox.

SizedBox(
 height: 80, 
 child: VerticalDivider(color: primaryColor),
)
Omach
  • 43
  • 6
1

you can try:

Container(
  color: Colors.grey,
  height: 30,
  width: 1,
),

It worked for me! :))

Jason
  • 11
  • 2
  • 2
    Use code sampler {} and put this Container( color: Colors.grey, height: 30, width: 1, ), inside of it so your answer is more readable to the oters. Thank you. – Sameera De Silva Apr 09 '21 at 05:27
1

The VerticalDivider Widget allows developers to add a vertical line that covers the available vertical space, usually in a row or column. It helps create clear distinctions between different parts or components of the user interface, providing visual separation without extra white space or margins.

VerticalDivider(
       color: Colors.white,
       width: 1.0,
),

Demo

  • Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. **Would you kindly [edit] your answer to include additional details for the benefit of the community?** – Jeremy Caney Jun 19 '23 at 02:25