Repository navigation
Unexpected top padding in ListView put inside scaffold with no appBar #14842
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.Affects or could affect many people, though not necessarily a specific customer.d: api docsIssues with https://api.flutter.dev/Issues with https://api.flutter.dev/frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packageswaiting for PR to land (fixed)A fix is in flightA fix is in flight
Milestone
Description
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:
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.Affects or could affect many people, though not necessarily a specific customer.d: api docsIssues with https://api.flutter.dev/Issues with https://api.flutter.dev/frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packageswaiting for PR to land (fixed)A fix is in flightA fix is in flight

Activity
cbracken commentedon Mar 1, 2018
/cc @HansMuller @Hixie
itsJoKr commentedon Mar 1, 2018
Just had this problem, top
SliverPaddingis set to20.0by default. Looking at docs I see:Hixie commentedon Mar 8, 2018
Yeah this is intentional. If you put a widget before the
ListView, you should wrap theListViewwith aMediaQuery.removePaddingwidget (withremoveTop: true).radzish commentedon Mar 8, 2018
Well, as long as this is documented I will close the issue
Hixie commentedon Mar 8, 2018
I'm not sure it's well-documented yet. If you can't find it in the documentation, please don't hesitate to reopen.
sergiandreplace commentedon Jun 13, 2018
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
Jasonthefirst commentedon Jun 15, 2018
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.)
tiagosito commentedon Jul 17, 2018
I did not find it in the documentation, is it there?
zoechi commentedon Aug 31, 2018
I assume this should not be closed because @Hixie added the
d: api docslabel after the issue was closed.8 remaining items
Remove top padding
douglasrosa0110 commentedon Aug 25, 2020
Tks a lot! This applies too when we need to show one scaffold into another scaffold
hovanhung98hust commentedon Sep 2, 2020
thanks, this work for me
inoas commentedon Oct 29, 2020
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.Hixie commentedon Oct 29, 2020
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.
nox-machina commentedon Feb 22, 2021
Well that was a life saver, thanks.
kamleshwebtech commentedon May 25, 2021
This solution helped me and removed my top space of GridView.builder widget:
Happy to get your help. Thanks dear.
github-actions commentedon Aug 1, 2021
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 -vand a minimal reproduction of the issue.