MediaQuery.of(context).padding.top is returning 0.0 when I'm using it with appBar. Why is that?
1,680
From this property's docs:
If you consumed this padding (e.g. by building a widget that envelops or accounts for this padding in its layout in such a way that children are no longer exposed to this padding), you should remove this padding for subsequent descendants in the widget tree by inserting a new MediaQuery widget using the MediaQuery.removePadding factory.
As the top padding is accounted for by the navBar, it is no longer exposed to widgets below it.
Author by
dipansh
Updated on December 26, 2022Comments
-
dipansh over 1 year
When I use
MediaQuery.of(context).padding.top
without the navBar in the widget tree then it returns me the actual true value.Reloaded 1 of 529 libraries in 637ms. I/flutter (31730): 24.0
But when I place the appBar into the widget tree then it returns me 0.0 only.
Reloaded 1 of 529 libraries in 764ms. I/flutter (31730): 0.0
Can someone please help that why it is happening?
-
dipansh over 3 yearsThanks, I figured it out now. I can collect the status bar size by calculating it before adding the navBar into the widget tree. :)
-
Ovidiu Uşvat over 2 yearscan you provide a code snippet?