Skip to content

In release mode we start off at 0x0 but we don't in debug mode #5259

Closed
@dragostis

Description

@dragostis
Contributor

Consider the following applet:

void main() {
  runApp(
    new MaterialApp(
      title: 'Bug Showcase',
      theme: new ThemeData(
        primarySwatch: Colors.blue
      ),
      home: new LayoutBuilder(
        builder: (BuildContext context, BoxConstraints constraints) {
          print(constraints);
          return new Container();
        }
      )
    )
  );
}

Running with flutter run this outputs:

I/flutter : BoxConstraints(w=360.0, h=640.0)

Running with flutter run --release this outputs:

I/flutter : BoxConstraints(w=0.0, h=0.0)
I/flutter : BoxConstraints(w=360.0, h=640.0)

This is problematic especially in the case of animating a widget based on its initial constraints.

Activity

eseidelGoogle

eseidelGoogle commented on Aug 5, 2016

@eseidelGoogle
Contributor

Presumably this is a race? @abarth does this mean we're doing a build before we know the screen size? FYI @chinmaygarde @jason-simmons

chinmaygarde

chinmaygarde commented on Aug 5, 2016

@chinmaygarde
Member

Window metrics can be updated at any time. Animations will have to account for the same in any case (not just the initial resize). Can you confirm you are getting window.onMetricsChanged(); at different spots on debug and release?

chinmaygarde

chinmaygarde commented on Aug 5, 2016

@chinmaygarde
Member

We can reorder initialization to make sure we call main after at least one resize.

dragostis

dragostis commented on Aug 5, 2016

@dragostis
ContributorAuthor

I'm trying

  ui.window.onMetricsChanged = () {
    print(ui.window.size);
  };

right before runApp(), but it doesn't print anything, regardless of whether or not I use --release.

abarth

abarth commented on Aug 5, 2016

@abarth
Contributor

The hook only takes one function and the framework is probably overwriting your function. You probably want to put your print in bindings.dart.

chinmaygarde

chinmaygarde commented on Aug 8, 2016

@chinmaygarde
Member

@abarth, @dragostis: I am not sure where the fix for this lies. Backing up the initial call to main till the first resize on all platforms is convoluted. However, we can change the initial main closure be something else, say, _start. This can then decide when to call main.

abarth

abarth commented on Aug 8, 2016

@abarth
Contributor

IMHO, apps should be robust to being sized 0x0 at startup. If the issue is inconsistency, maybe we should make that happen every time instead of having it be a race.

dragostis

dragostis commented on Aug 8, 2016

@dragostis
ContributorAuthor

@abarth Sure, the only issue might be the transition from 0x0 to WxH that the user might not consider. Anyway, this is not really user-facing.

abarth

abarth commented on Aug 8, 2016

@abarth
Contributor

Exactly. We should force developers to consider those cases. Otherwise we'll have to slow down app launch to ensure that the width and height are always available at startup.

Hixie

Hixie commented on Sep 9, 2016

@Hixie
Contributor

The complex_layout benchmark triggers this in a way that crashes the framework, fwiw.

modified the milestone: Flutter 1.0 on Sep 12, 2016
Hixie

Hixie commented on Oct 26, 2016

@Hixie
Contributor

This also affects --no-hot debug mode.

changed the title [-]Running in release mode pushed zero box constraints.[/-] [+]In release mode we start off at 0x0 but we don't in debug mode[/+] on May 6, 2017
Hixie

Hixie commented on Nov 14, 2017

@Hixie
Contributor

Closing this in favour of #6537.

added a commit that references this issue on May 17, 2018
github-actions

github-actions commented on Aug 15, 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.

locked as resolved and limited conversation to collaborators on Aug 15, 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

    a: animationAnimation APIsframeworkflutter/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

        Participants

        @chinmaygarde@abarth@Hixie@dragostis@eseidelGoogle

        Issue actions

          In release mode we start off at 0x0 but we don't in debug mode · Issue #5259 · flutter/flutter