Skip to content

MediaQuery.of(context).size.height returns 0 on startup in release mode #25827

@yunyu

Description

@yunyu

I have a widget which is a member of a stack that's in the body of Scaffold:

MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
            body: Stack(
                children: [MyWidget()],
                alignment: Alignment.bottomCenter)));
  }

When I log MediaQuery.of(context).size.height in MyWidget's build() function, I get the following output in release mode:

12-27 18:43:39.650 12694 12740 I flutter : Context height: 0.0
12-27 18:43:39.854 12694 12740 I flutter : Context height: 731.4285714285714

The behavior is as expected in debug mode (height is never 0.0). I am doing some calculations with this
value that would result in some widgets having infinite height, which causes the application to freeze on startup.

Metadata

Metadata

Assignees

No one assigned

    Labels

    d: api docsIssues with https://api.flutter.dev/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