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

Time:01-24

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.

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?

CodePudding user response:

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.

CodePudding user response:

if you are using card widget for this card widget is giving 4 margin at all sides buy default you can eliminate this by giving it explicit zero margin

Card(
   margin: EdgeInsets.zero,
   child: ///Your widget
 )
  • Related