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

Adding space between containers in a listview

i’m new to flutter and i’m trying to add some space between containers in a listview, literally tried everything but failed at it, I want to divide them containers for a better visualization of the items inside of the list, thanks in advance!

Code:

body: Column(
  children: <Widget>[
    Expanded(
      child: ListView.builder(
        padding: EdgeInsets.all(15),
        itemCount: 6,
        itemBuilder: (BuildContext context, int index) {
          return Row(
            children: [
              SizedBox(
                width: 70,
                child: AspectRatio(
                  aspectRatio: 0.88,
                  child: Container(
                    padding: EdgeInsets.all(22),
                    decoration: BoxDecoration(
                      color: Color(0xFFF5F6F9),
                      borderRadius: BorderRadius.circular(15),
                    ),
                    child: Image.asset(
                      'assets/syringe.png',
                    ),
                  ),
                ),
              ),
              SizedBox(width: 20),
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    "Type d'analyse",
                    style: TextStyle(color: Colors.black, fontSize: 16),
                    maxLines: 2,
                  ),
                  SizedBox(height: 10),
                  Text.rich(
                    TextSpan(
                      text: "Date: ",
                      style: TextStyle(
                          fontWeight: FontWeight.w600,
                          color: kPrimaryColor),
                    ),
                  ),
                ],
              ),
            ],
          );
        },
      ),
    )
  ],
),

Screenshot:

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

enter image description here

>Solution :

Use ListView.separated instead of ListView.builder

It works exactly the same but with the added separatorBuilder parameter. Which could be something like

  separatorBuilder: (BuildContext context, int index) => const Divider()
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