• LongCatIsLooong's avatar
    Add `InlineSpan.visitDirectChildren` (#125656) · f704c689
    LongCatIsLooong authored
    I'd like to find out the `fontSize` of a `PlaceholderSpan`, and currently there doesn't seem to be a way to do `TextStyle` cascading in the framework:
    
     `InlineSpan.visitChildren` traverses the entire `InlineSpan` tree using a preorder traversal, and nodes that don't have "content" will be skipped (https://master-api.flutter.dev/flutter/painting/InlineSpan/visitChildren.html): 
    
    > Walks this [InlineSpan](https://master-api.flutter.dev/flutter/painting/InlineSpan-class.html) and any descendants in pre-order and calls visitor for each span that has content.
    
    which makes it impossible to do `TextStyle` cascading in the framework: 
    - `InlineSpan`s with a non-null `TextStyle` but has no content will be skipped
    - `visitChildren` doesn't directly expose the hierarchy, it only gives information about the flattened tree.
    
    This doesn't look like a breaking change, most internal customers are extending `WidgetSpan` which has a concrete implementation of the new method.
    
    Alternatively I could create a fake `ui.ParagraphBuilder` and record the `ui.TextStyle` at the top of the stack when `addPlaceholder` is called. But `ui.TextStyle` properties are not exposed to the framework.
    f704c689
text_span_test.dart 15.1 KB