Skip to content

RenderFlex should not use defaultComputeDistanceToFirstActualBaseline to calculate its baseline in Axis.vertical #145739

Closed

Description

@LongCatIsLooong

VerticalDirection.up reorders its children. This will be a breaking change.

  test('Vertical Flex Baseline', () {
    const BoxConstraints square = BoxConstraints.tightFor(width: 100.0, height: 100.0);
    final RenderConstrainedBox box1 = RenderConstrainedBox(
      additionalConstraints: square,
      child: RenderFlowBaselineTestBox()
        ..gridCount = 1
        ..baselinePlacer = (double height) => 10,
    );
    final RenderConstrainedBox box2 = RenderConstrainedBox(
      additionalConstraints: square,
      child: RenderFlowBaselineTestBox()
        ..gridCount = 1
        ..baselinePlacer = (double height) => 10,
    );
    final RenderFlex flex = RenderFlex(
      textDirection: TextDirection.ltr,
      children: <RenderBox>[box1, box2],
      direction: Axis.vertical,
    );
    layout(flex, phase: EnginePhase.paint);

    // We can't call the getDistanceToBaseline method directly. Check the dry
    // baseline instead, and in debug mode there are asserts that verify
    // the two methods return the same results.
    expect(flex.getDryBaseline(flex.constraints, TextBaseline.alphabetic), 10);

    flex.mainAxisAlignment = MainAxisAlignment.end;
    pumpFrame(phase: EnginePhase.paint);
    expect(flex.getDryBaseline(flex.constraints, TextBaseline.alphabetic), 410);

    flex.verticalDirection = VerticalDirection.up;
    pumpFrame(phase: EnginePhase.paint);
    expect(flex.getDryBaseline(flex.constraints, TextBaseline.alphabetic), 10);

    flex.mainAxisAlignment = MainAxisAlignment.start;
    pumpFrame(phase: EnginePhase.paint);
    expect(flex.getDryBaseline(flex.constraints, TextBaseline.alphabetic), 410);
  });

Activity

  1. added
    in triagePresently being triaged by the triage team
    on Mar 26, 2024
  2. huycozy commented on Mar 26, 2024

    @huycozy
    Member

    Hi @LongCatIsLooong
    RenderFlowBaselineTestBox is not defined. Could you also share it?

  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Mar 26, 2024
  4. github-actions commented on Apr 16, 2024

    @github-actions

    Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now.
    If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones.
    Thanks for your contribution.

  5. github-actions commented on Apr 30, 2024

    @github-actions

    Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now.
    If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones.
    Thanks for your contribution.

  6. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Apr 30, 2024
  7. removed
    in triagePresently being triaged by the triage team
    on May 1, 2024
  8. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    a: layoutSystemChrome and Framework's Layout Issues
    on May 4, 2024
  9. LongCatIsLooong commented on May 23, 2024

    @LongCatIsLooong
    ContributorAuthor

    @Hixie in a vertical RenderFlex with VerticalDirection.up, which child's baseline should be used? The documentation of computeDistanceToActualBaseline says it

    Returns the distance from the y-coordinate of the position of the box to the y-coordinate of the first given baseline in the box's contents, if any, or null otherwise.

    How do I interpret "the first given baseline" here? For multi-child containers, does it mean "the baseline with the smallest y-offset"?

  10. Hixie commented on May 23, 2024

    @Hixie
    Contributor

    If I recall correctly, the "first child" is intended to be the first one in the child list (the one that firstChild points to).

  11. Hixie commented on May 23, 2024

    @Hixie
    Contributor

    (It's definitely not automatically the one with the smallest y-offset, in fact that's often the wrong child (for example consider a stack). It's also not always the first child that you want, for example a Material text field explicitly doesn't want to use the label for its baseline, since that moves around; it wants to use the user-editable text in the text field.)

  12. LongCatIsLooong commented on May 23, 2024

    @LongCatIsLooong
    ContributorAuthor

    Ah so if I have a column with VerticalDirection.up, the expected behavior is to use the bottom-most child with a baseline?

    for example consider a stack

    Stacks do use the highest baseline it seems: https://api.flutter.dev/flutter/rendering/RenderStack/computeDistanceToActualBaseline.html

  13. LongCatIsLooong commented on May 23, 2024

    @LongCatIsLooong
    ContributorAuthor

    in fact that's often the wrong child

    There doesn't seem to be a fast & easy remedy for that besides writing a custom RenderObject? Does it sound reasonable to introduce a ParentDataWidget to specify the baseline child then (I think we are allowed to have more than one ParentDataWidget on a render object now)?

  14. Hixie commented on May 23, 2024

    @Hixie
    Contributor

    Ah so if I have a column with VerticalDirection.up, the expected behavior is to use the bottom-most child with a baseline?

    I mean honestly at this point given how much content exists that depends on this, I would say the expected behaviour is probably whatever we do. If we change it, we're going to break people in really subtle ways.

    Stacks do use the highest baseline it seems: https://api.flutter.dev/flutter/rendering/RenderStack/computeDistanceToActualBaseline.html

    Heh, figures. :-)

    There doesn't seem to be a fast & easy remedy for that besides writing a custom RenderObject?

    The IgnoreBaseline widget is the usual remedy, but in general, writing a custom RenderObject is probably the way to go if you care about the layout and baseline positions and so on.

    Does it sound reasonable to introduce a ParentDataWidget to specify the baseline child then (I think we are allowed to have more than one ParentDataWidget on a render object now)?

    I'm not sure what problem we're trying to solve here so it's hard for me to evaluate.

  15. LongCatIsLooong commented on May 23, 2024

    @LongCatIsLooong
    ContributorAuthor

    The IgnoreBaseline widget is the usual remedy

    Ah clever. Thanks I'll close this then.

  16. github-actions commented on Jun 6, 2024

    @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 Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

a: layoutSystemChrome and Framework's Layout Issuesframeworkflutter/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