Skip to content

_cachedBaselines not clear when relayout #101179

Closed

Description

@hackware1993
@override
void markNeedsLayout() {
  if ((_cachedBaselines != null && _cachedBaselines!.isNotEmpty) ||
      (_cachedIntrinsicDimensions != null && _cachedIntrinsicDimensions!.isNotEmpty) ||
      (_cachedDryLayoutSizes != null && _cachedDryLayoutSizes!.isNotEmpty)) {
    // If we have cached data, then someone must have used our data.
    // Since the parent will shortly be marked dirty, we can forget that they
    // used the baseline and/or intrinsic dimensions. If they use them again,
    // then we'll fill the cache again, and if we get dirty again, we'll
    // notify them again.
    **_cachedBaselines?.clear();**
    _cachedIntrinsicDimensions?.clear();
    _cachedDryLayoutSizes?.clear();
    if (parent is RenderObject) {
      markParentNeedsLayout();
      return;
    }
  }
  super.markNeedsLayout();
}

_cachedBaselines only be cleared in markNeedsLayout,but i think it should also be cleared in layout(when parent relayout it,)

Activity

  1. hackware1993 commented on Apr 1, 2022

    @hackware1993
    Author

    I'm writing a custom layout with RenderBox, this layout will use the baseline of the child element, when I change the size of the child element and re-layout it, I still get the old baseline. This is wrong. Child elements should recalculate the baseline based on the new self size.

  2. darshankawar commented on Apr 1, 2022

    @darshankawar
    Member

    @hackware1993
    Please provide flutter doctor -v, a complete runnable but minimal reproducible code sample along with expected vs actual result.

    Thanks.

  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Apr 1, 2022
  4. hackware1993 commented on Apr 1, 2022

    @hackware1993
    Author

    flutter version: v2.10.3 stable

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Apr 1, 2022
  6. darshankawar commented on Apr 1, 2022

    @darshankawar
    Member

    @hackware1993
    Also a complete runnable but minimal reproducible code sample as requested earlier.

  7. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Apr 1, 2022
  8. hackware1993 commented on Apr 2, 2022

    @hackware1993
    Author

    image
    My temporary solution is to change the source code of the local flutter framework.

  9. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Apr 2, 2022
  10. darshankawar commented on Apr 4, 2022

    @darshankawar
    Member

    Keeping this open and labeling for further investigation from the team.

  11. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    in triagePresently being triaged by the triage team
    and removed
    in triagePresently being triaged by the triage team
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Apr 4, 2022
  12. 6 remaining items

  13. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    platform-webWeb applications specifically
    a: layoutSystemChrome and Framework's Layout Issues
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Apr 5, 2022
  14. self-assigned this
    on Apr 6, 2022
  15. xu-baolin commented on Apr 7, 2022

    @xu-baolin
    Member

    Repro Steps

    1, Run the code on a desktop platform
    2, Resize the app window
    3, Observer the placeholder position

    Expect

    20220407_114446.mp4

    Actual

    20220407_114740.mp4

    Code

    import 'package:flutter/material.dart';
    import 'package:flutter/rendering.dart';
    
    void main() {
      runApp(MaterialApp(
        title: 'Issue report',
        home: BaselineUse(),
      ));
    }
    
    class BaselineUse extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(title: const Text('Issue report'),),
          body: Baseline(
            baseline: 0.0,
            baselineType: TextBaseline.alphabetic,
            child: Column(
              children: const [
                Expanded(
                  child: MyWidget(
                    child: Placeholder(),
                  ),
                )
              ],
            ),
          ),
        );
      }
    }
    
    class MyWidget extends SingleChildRenderObjectWidget {
      const MyWidget({Key? key, required Widget child})
          : super(key: key, child: child);
    
      @override
      RenderObject createRenderObject(BuildContext context) {
        return RenderMyWidget();
      }
    }
    
    class RenderMyWidget extends RenderProxyBox {
      late Size boxSize;
    
      @override
      double? computeDistanceToActualBaseline(TextBaseline baseline) {
        if (hasSize) {
          return boxSize.height / 2.0;
        } else {
          return 0.0;
        }
      }
    
      @override
      void layout(Constraints constraints, {bool parentUsesSize = false}) {
        super.layout(constraints, parentUsesSize: parentUsesSize);
        boxSize = size;
      }
    }
    
  16. added
    P2Important issues not at the top of the work list
    on Apr 7, 2022
  17. added
    r: fixedIssue is closed as already fixed in a newer version
    on May 6, 2022
  18. github-actions commented on May 20, 2022

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

  19. locked as resolved and limited conversation to collaborators on May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: desktopRunning on desktopa: layoutSystemChrome and Framework's Layout Issuesfound in release: 2.10Found to occur in 2.10found in release: 2.13Found to occur in 2.13frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specificallyr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions