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

Flutter: Why does my ListView/ ListBuilder widget build with an empty space before my widgets?

Notice the area above the first card in the ListView. I want my widgets to start where that are is, not below it

As you can see above my ListView.builder is placing a margin prior to the actual widgets within the list. Is there any way to avoid this?

I’ve looked throughout the widget tree for all of my alignment, padding and margins and I don’t believe that it is that. Additionally, I made a new test ListView to see if it is a problem with that Widget itself and I feel that it is.

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

Notice the area above the Text widgets

This is the code for the above image.

Container(
                margin: const EdgeInsets.all(60),
                decoration: BoxDecoration(
                    border: Border.all(color: Colors.black, width: 5)),
                height: 20,
                width: 20,
                child: ListView(
                  children: const [
                    Text("Test"),
                    Text("Test"),
                    Text("Test"),
                  ],
                )),

How do I remove or ignore this empty space?

>Solution :

Try to remove the padding of your ListView. Set this inside your ListView.

  padding: EdgeInsets.zero,

By default, ListView will automatically pad the list’s scrollable extremities to avoid partial obstructions indicated by MediaQuery’s padding. To avoid this behavior, override with a zero padding property.

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