Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter divider widget not appearing

Tags:

flutter

I'm currently learning how to build apps using the Flutter SDK and Android Studio. My problem is that I need to add a Divider widget between the 'Administrative' text and the rest of the Card but as you can see in the screenshot below, the divider isn't showing up. I've tried changing the size (In which case the space between the two texts just increases) and I've tried setting the color to see if it was defaulting to transparent on my phone. Nothing works!

Here's my code for the Card Widget State:

class BBSCardState extends State<BBSCard>{   @override   Widget build(BuildContext context) {     return new Padding(       padding: const EdgeInsets.only(top: 16.0, bottom: 16.0, left: 12.0, right: 12.0),       child: new Card(         child: new Row(           children: <Widget>[             new Column(               mainAxisSize: MainAxisSize.min,               children: <Widget>[                 new Padding(                   padding: const EdgeInsets.only(top: 22.0, bottom: 8.0),                   child: new Text("Administrative", style: new TextStyle(color: new Color.fromARGB(255, 117, 117, 117), fontSize: 32.0, fontWeight: FontWeight.bold)),                 ),                 new Divider(),                 new Text("text")               ],             ),           ],           mainAxisSize: MainAxisSize.max,           mainAxisAlignment: MainAxisAlignment.center,         )       )     );   } } 

And here's the screenshot of what the card looks like:

The divider does not appear between the two texts

Also: Is there any way to increase the size of the actual line from the Divider? (Not just the spacing)

Thanks!

like image 528
Nathan Bird Avatar asked Mar 03 '18 20:03

Nathan Bird


People also ask

How do you show the divider in Flutter?

If you needed the row widget there, another way to provide the column width for the Divider class would be to wrap the Column Widget with something like Expanded - then your code would work.

How do you use divider widget 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 set the divider width in Flutter?

“divider width 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.


2 Answers

You could remove Row, then Column would take all available space and Divider would have width.

@override Widget build(BuildContext context) {   return new Padding(     padding: const EdgeInsets.only(         top: 16.0, bottom: 16.0, left: 12.0, right: 12.0),     child: new Card(       child: new Column(         mainAxisSize: MainAxisSize.min,         children: <Widget>[           new Padding(             padding: const EdgeInsets.only(top: 22.0, bottom: 8.0),             child: new Text("Administrative",                 style: new TextStyle(                     color: new Color.fromARGB(255, 117, 117, 117),                     fontSize: 32.0,                     fontWeight: FontWeight.bold)),           ),           new Divider(             color: Colors.red,           ),           new Text("text")         ],       ),     ),   ); } 

Result

To make custom divider you could check implementation of Divider and adjust it. E.g. replace Divider with

new SizedBox(   height: 10.0,   child: new Center(     child: new Container(       margin: new EdgeInsetsDirectional.only(start: 1.0, end: 1.0),       height: 5.0,       color: Colors.red,     ),   ), ) 

CustomDivider

like image 145
German Saprykin Avatar answered Nov 15 '22 19:11

German Saprykin


it was happening to me but I found out that this property solves it: thickness

 child: Divider(                 color: Colors.teal.shade100,                 thickness: 1.0,               ), 
like image 45
Neo Avatar answered Nov 15 '22 20:11

Neo