Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a horizontal line in flutter row widgets?

Tags:

flutter

dart

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

like image 673
S. M. Asif Avatar asked Jul 10 '19 06:07

S. M. Asif


People also ask

How do you add a line separator in Flutter?

If you have a list of widgets, you may need to add a separator between the widgets. 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.

How do you make a horizontal divider in Flutter?

“horizontal divider in flutter” Code Answer'sindent: 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 use a Row widget in Flutter?

If we want to make a scrollable list of row widgets, we need to use the ListView widget. We can control how a row widget aligns its children based on our choice using the property crossAxisAlignment and mainAxisAlignment. The row's cross-axis will run vertically, and the main axis will run horizontally.


1 Answers

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             )           ],         ),       )     ],   )), ); 
like image 117
Sven Avatar answered Oct 01 '22 17:10

Sven