Skip to content

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

Description

@dragostis

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

  1. 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

  2. chinmaygarde commented on Aug 5, 2016

    @chinmaygarde
    Contributor

    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?

  3. chinmaygarde commented on Aug 5, 2016

    @chinmaygarde
    Contributor

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

  4. 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.

  5. 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.

  6. chinmaygarde commented on Aug 8, 2016

    @chinmaygarde
    Contributor

    @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.

  7. 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.

  8. 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.

  9. 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.

  10. Hixie commented on Sep 9, 2016

    @Hixie
    Contributor

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

  11. modified the milestone: on Sep 12, 2016
  12. Hixie commented on Oct 26, 2016

    @Hixie
    Contributor

    This also affects --no-hot debug mode.

  13. 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
  14. Hixie commented on Nov 14, 2017

    @Hixie
    Contributor

    Closing this in favour of #6537.

  15. added a commit that references this issue on May 17, 2018
  16. 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.

  17. 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

      Issue actions