Skip to content

MediaQuery.of(context).padding can return EdgeInsets.zero #5483

Closed

Description

@HansMuller

When running on the Android emulator and occasionally when running Android native, MediaQuery.of(context).padding.top is zero the first time it's called at Widget initState() time. Calling it later, e.g. at build() time instead appears to consistently return the status bar's actual height.

This came up on the gallery demo's home screen, see #5368

Activity

  1. eseidelGoogle commented on Aug 18, 2016

    @eseidelGoogle
    Contributor

    This sounds related to #5259 ?

  2. Hixie commented on Aug 18, 2016

    @Hixie
    Contributor

    In general MediaQuery.of() can return different values each time. That's why it's an InheritedWidget. Caching the value in initState is going to lead to bugs regardless.

  3. HansMuller commented on Aug 18, 2016

    @HansMuller
    ContributorAuthor

    The MediaQuery definitely didn't belong in initState().

    On the other hand it seemed odd to report that the status bar's height was 0 and then ~25 later on, since the status bar is static. However I think the gist of this and #5259 is that developers need to deal with startup time zero-to-actual-value geometry changes.

  4. github-actions commented on Sep 6, 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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions