S. M. Asif
S. M. Asif

Reputation: 3709

How to draw a horizontal line in flutter row widgets?

In my flutter project, I have initialized a Row. Inside that, I created some Texts in a column and after that, I want to add a line but it is not showing anything. I have used Expanded for that reason and followed the given solutions-

Horizontal divider with text in the middle in Flutter?

But none of them worked either.

Here's the image of my code output-

enter image description here

Here's my code-

Container(
      color:Colors.white,
      child: (
        Row(
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Image(
                  height: 100,
                  width: 100,
                  image: NetworkImage("https://www.gstatic.com/webp/gallery/1.jpg"),
                ),
            ),
            Column(
              children: <Widget>[
                Text("Book Name"),
                Text("Author name"),

                Divider(
                  color: Colors.black,
                )
              ],
            )
          ],
        )
      ),
    ),

So, I need a line below the two texts and show it like the below picture-

enter image description here

Upvotes: 91

Views: 199642

Answers (6)

Maryam Azhdari
Maryam Azhdari

Reputation: 1319

Container( color: Colors.white, height: 1, width: 100, );

Upvotes: 0

Hasan ko&#231;
Hasan ko&#231;

Reputation: 169

use :
Divider(),

source : flutter.dev

Upvotes: 4

Kenart
Kenart

Reputation: 335

If you know exactly how long you want the line to be. You can wrap the Divider with a SizedBox specifying the width of the line with the SizedBox properties.

Upvotes: 2

Shehzad Ahmad
Shehzad Ahmad

Reputation: 131

Easy Pezy Lemon Squeezy

Its simple, see take a container, do not mention its width, because it will take the space dynamically and then only give the color to the lower border of the radius.

Container(
                              child: Text(
                                'Your Text Here',
                              ),
                              decoration: BoxDecoration(
                                border: Border(
                                  bottom: BorderSide(color: Colors.black),
                                ),
                              ),
                            ),

Upvotes: 8

Sven
Sven

Reputation: 3414

Try wrapping you Column in an Expanded so the Divider knows how much space to occupy.

Container(
  color: Colors.white,
  child: (Row(
    children: <Widget>[
      // ...
      Expanded(
        child: Column(
          children: <Widget>[
            Text("Book Name"),
            Text("Author name"),
            Divider(
              color: Colors.black
            )
          ],
        ),
      )
    ],
  )),
);

Upvotes: 176

Abbas.M
Abbas.M

Reputation: 3384

The idea is that you placed your divider inside a column whereas the divider by default is horizontal so it doesn't have enough space to occupy. If you change your height property for the divider you can see it clearly.

If you want you can wrap your divider in a row or perhaps make the divider part of the outer row though you might have to fix its alignment and wrap it in an expanded. You can also wrap the column in an expanded so it occupies all enough space for the divider to appear.

I'd do the code for you but I only have part of the code of what's displayed + it shouldn't be too difficult. If you needed more help let me know!

Upvotes: 6

Related Questions