Skip to content

Unexpected top padding in ListView put inside scaffold with no appBar #14842

Closed

Description

@radzish

If you put ListView somewhere inside Scaffold having no appBar, ListView has top padding. There is no padding if appBar is present. There is no padding if you specify EdgeInsets.zero padding for ListView explicitly. See following code snipped for example

...
    return new MaterialApp(
      home: new Scaffold(
//        appBar: new AppBar(
//          title: new Text("test"),
//        ),
        body: new Column(
          children: <Widget>[
            new Container(
              child: new Center(
                  child: new Text("some top widget")
              ),
              decoration: new BoxDecoration(
                color: Colors.red,
              ),
              height: 100.0,
            ),
            new Expanded(
              child: new ListView(
                children: items,
//                padding: EdgeInsets.zero, // explicit padding as a workaround
              ),
            ),
          ],
        ),
      ),
    );
...

See screenshot:

bug

Flutter Doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (on Linux, locale en_US.UTF-8, channel master)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[✓] Android Studio (version 3.0)
[!] IntelliJ IDEA Ultimate Edition (version 2017.3)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.20.1)
[✓] Connected devices

Activity

  1. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    on Mar 1, 2018
  2. cbracken commented on Mar 1, 2018

    @cbracken
    Member
  3. itsJoKr commented on Mar 1, 2018

    @itsJoKr

    Just had this problem, top SliverPadding is set to 20.0 by default. Looking at docs I see:

    /// 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.
    
  4. Hixie commented on Mar 8, 2018

    @Hixie
    Contributor

    Yeah this is intentional. If you put a widget before the ListView, you should wrap the ListView with a MediaQuery.removePadding widget (with removeTop: true).

  5. radzish commented on Mar 8, 2018

    @radzish
    Author

    Well, as long as this is documented I will close the issue

  6. Hixie commented on Mar 8, 2018

    @Hixie
    Contributor

    I'm not sure it's well-documented yet. If you can't find it in the documentation, please don't hesitate to reopen.

  7. sergiandreplace commented on Jun 13, 2018

    @sergiandreplace

    I had this same issue and after some search this is the only exact answer I've found. Maybe is worth to create a short entry on documentation about window measurement and specific cases

  8. Jasonthefirst commented on Jun 15, 2018

    @Jasonthefirst

    Found this topic because I thought this is maybe a bug or I did oversee something. So maybe some more info is needed. (I would prefer a method to turn this off inside the listview, too. This would be easier.)

  9. tiagosito commented on Jul 17, 2018

    @tiagosito

    I did not find it in the documentation, is it there?

  10. zoechi commented on Aug 31, 2018

    @zoechi
    Contributor

    I assume this should not be closed because @Hixie added the d: api docs label after the issue was closed.

  11. reopened this on Aug 31, 2018
  12. added this to the milestone on Feb 13, 2019
  13. 8 remaining items

  14. added a commit that references this issue on Apr 30, 2020
  15. added
    P2Important issues not at the top of the work list
    on May 29, 2020
  16. self-assigned this
    on Jul 2, 2020
  17. modified the milestones: , 1.21 - July 2020 on Jul 2, 2020
  18. douglasrosa0110 commented on Aug 25, 2020

    @douglasrosa0110

    Yeah this is intentional. If you put a widget before the ListView, you should wrap the ListView with a MediaQuery.removePadding widget (with removeTop: true).

    Tks a lot! This applies too when we need to show one scaffold into another scaffold

  19. hovanhung98hust commented on Sep 2, 2020

    @hovanhung98hust

    Just had this problem, top SliverPadding is set to 20.0 by default. Looking at docs I see:

    /// 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.
    

    thanks, this work for me

  20. inoas commented on Oct 29, 2020

    @inoas

    This was really an unexpected implicit and hidden that made you doubt your own sanity (until adding padding: EdgeInsets.zero).

    @Hixie (the guy who thought me CSS box model on Freenode IRC about 18-20yrs ago <3) :
    Is this setting padding: okay or ist a wrapping in MediaQuery.removePadding(... recommended/must-have. Latter is much more code and convoluted to the uninitiated eyes.

  21. Hixie commented on Oct 29, 2020

    @Hixie
    Contributor

    Once you know about SafeArea it makes more sense. The problem is that in trying to make SafeArea work automatically without having to think about it, we also require that in cases where you do things it can't handle you have to handle it. I don't think we have a good solution to this other than improving the docs. If this is still confusing then we should add another section to the "troubleshooting" part of the Scaffold docs. Please do file a new bug if you'd like us to do that.

  22. nox-machina commented on Feb 22, 2021

    @nox-machina

    Yeah this is intentional. If you put a widget before the ListView, you should wrap the ListView with a MediaQuery.removePadding widget (with removeTop: true).

    Well that was a life saver, thanks.

  23. kamleshwebtech commented on May 25, 2021

    @kamleshwebtech

    Yeah this is intentional. If you put a widget before the ListView, you should wrap the ListView with a MediaQuery.removePadding widget (with removeTop: true).

    This solution helped me and removed my top space of GridView.builder widget:

    Container(
                child: MediaQuery.removePadding(
                  removeTop: true,
                  context: context,
                  child: GridView.builder(
    

    Happy to get your help. Thanks dear.

  24. github-actions commented on Aug 1, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  25. locked as resolved and limited conversation to collaborators on Aug 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.d: api docsIssues with https://api.flutter.dev/frameworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packageswaiting for PR to land (fixed)A fix is in flight

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions