Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

space between divider and container in flutter

The divider is not adjusting as I need, All the stuff inside in Column Widget and not able to set vertical line.

 Container(
       decoration: BoxDecoration(color: Colors.grey[300]),
        child:
       Row(
         mainAxisAlignment: MainAxisAlignment.start,
         mainAxisSize: MainAxisSize.max,
         children: <Widget>[
           Expanded(child: TextFormField(
             style: new TextStyle(color: Colors.grey),
             decoration: InputDecoration(
               border: InputBorder.none,
               prefixIcon: Icon(Icons.search,color: Colors.grey,size: 30.0,),
               hintStyle: TextStyle(color: Colors.grey,fontSize: 18.0),
               hintText: 'Search',
             ),),),

           IconButton(onPressed:(){},icon: Image.asset('assets/images/grid.png',fit: BoxFit.contain ,),),
           Container(decoration: BoxDecoration(color: Colors.grey),width: 5.0,child: Text(''),),
           IconButton(onPressed:(){},icon: Image.asset('assets/images/list.png',fit: BoxFit.contain ,),),

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

I need this enter image description here

and getting this

enter image description here

like image 603
Farhana Naaz Ansari Avatar asked Jan 25 '19 09:01

Farhana Naaz Ansari


People also ask

How do you add spacing in Flutter?

The Spacer widget in Flutter, allows you to add an empty space that you can adjust to match your design. By default, it takes all the available space and shifts the adjacent widget to the far side. Using the flex property of the Spacer widget, you can control the space between widgets.

What is the use of spacing in flutter?

The most common usage for Spacer is for creating adjustable spaces between widgets in a Flex container, such as Row or Column. Though Flutter provides some predefined alignments like spaceBetween, spaceAround, and spaceEvenly, sometimes we may need to set custom spacing.

How to use divider and verticaldivider in flutter?

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.

How to set space between elements in flutter widget?

How to Set Space Between Elements In Flutter? Row widget has a property called MainAxisAlignment. start – Place the children as close to the start of the main axis as possible. end – Place the children as close to the end of the main axis as possible. center – Place the children as close to the middle of the main axis as possible.

What is container class in flutter?

Container class in Flutter. Container class in flutter is a convenience widget that combines common painting, positioning, and sizing of widgets. A Container class can be used to store one or more widgets and position it on the screen according to our convenience. Basically a container is like a box to store contents.


2 Answers

Just give a height of 1 to the divider.

Divider(height: 1)

This will remove any padding it has.

Simple solution : Works Flawlessly 🎊🚀

Full code below :

ListView.separated(
     itemCount: 10,
     separatorBuilder: (_ , __ ) => Divider(height:1),
     itemBuilder: (BuildContext context, int index) {
       return ListTile(
         title: Text('item $index'),
       );
     },
);
like image 78
Natesh bhat Avatar answered Oct 12 '22 15:10

Natesh bhat


Just remove divider replace with this line

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

and set Column

    crossAxisAlignment: CrossAxisAlignment.stretch,
like image 23
Govaadiyo Avatar answered Oct 12 '22 15:10

Govaadiyo