Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Drawing 2 lines between Dart Flutter listView items

I have an application like this:

enter image description here

There is a line between each item. I want a line between every 2 item, not every item.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Codes:

body: Container(
  padding: EdgeInsets.all(7),
  child: Column(
    
    children: [
      
      Text(defaultFlag, style: TextStyle(fontSize: 24),),
      SizedBox(height: 10,),


      Expanded(
        
        child: ListView.separated(
          itemCount: levels.length,
          separatorBuilder: (context, index) => Divider(
            thickness: 2,
            color: Colors.black,
          
          ),
          itemBuilder: (BuildContext context, int index) {
            return Padding(
              padding: const EdgeInsets.all(2.0),
              child: Container(
                child: InkWell(
                  child: Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(10),
                      border: Border.all(color: Colors.black),
                    ),
                    child: ListTile(
                      leading: languageLevelIcon(levels[index].languageLevelName,),
                      title: Text(levels[index].languageLevelName, style: TextStyle(fontSize: 25),),
                      trailing: Icon(Icons.arrow_forward_ios, color: Colors.black,),
                      
                      iconColor: Colors.black,
                    ),
                    
                    ),
                  onTap: () {
                    print("tıklandı " + levels[index].languageLevelName);
                  },
                ),
                
              ),
              
            );
          },
        ),
      ),
    ],
  ),
),

So there will be a line between A2 and B1, and between B2 and C1. I want a line between both items. How can I do it?

>Solution :

As @Jim has mentioned,

ListView.separated(
      itemCount: levels.length,
      separatorBuilder: (context, index) => index % 2 != 0 ? Divider(
        thickness: 2,
        color: Colors.black,
      ) : SizedBox(),
      itemBuilder: (context, i) {
        return <Your list tile>,
        );
      },
    ),
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading