Skip to content

Commit

Permalink
Introduce methods for computing the baseline location of a RenderBox …
Browse files Browse the repository at this point in the history
…without affecting the current layout (flutter#144655)

Extracted from flutter#138369

Introduces `RenderBox.{compute,get}DryBaseline` for computing the baseline location in `RenderBox.computeDryLayout`.
  • Loading branch information
LongCatIsLooong committed Mar 18, 2024
1 parent f704560 commit 98369bd
Show file tree
Hide file tree
Showing 12 changed files with 651 additions and 225 deletions.
5 changes: 4 additions & 1 deletion packages/flutter/lib/src/material/input_decorator.dart
Expand Up @@ -1316,7 +1316,10 @@ class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin

@override
double computeDistanceToActualBaseline(TextBaseline baseline) {
return _boxParentData(input!).offset.dy + (input?.computeDistanceToActualBaseline(baseline) ?? 0.0);
final RenderBox? input = this.input;
return input == null
? 0.0
: _boxParentData(input).offset.dy + (input.computeDistanceToActualBaseline(baseline) ?? 0.0);
}

// Records where the label was painted.
Expand Down
6 changes: 4 additions & 2 deletions packages/flutter/lib/src/material/list_tile.dart
Expand Up @@ -1249,10 +1249,12 @@ class _RenderListTile extends RenderBox with SlottedContainerRenderObjectMixin<_
}

@override
double computeDistanceToActualBaseline(TextBaseline baseline) {
double? computeDistanceToActualBaseline(TextBaseline baseline) {
assert(title != null);
final BoxParentData parentData = title!.parentData! as BoxParentData;
return parentData.offset.dy + title!.getDistanceToActualBaseline(baseline)!;
final BaselineOffset offset = BaselineOffset(title!.getDistanceToActualBaseline(baseline))
+ parentData.offset.dy;
return offset.offset;
}

static double? _boxBaseline(RenderBox box, TextBaseline baseline) {
Expand Down
10 changes: 6 additions & 4 deletions packages/flutter/lib/src/material/toggle_buttons.dart
Expand Up @@ -1175,11 +1175,13 @@ class _SelectToggleButtonRenderObject extends RenderShiftedBox {
}

@override
double computeDistanceToActualBaseline(TextBaseline baseline) {
double? computeDistanceToActualBaseline(TextBaseline baseline) {
// The baseline of this widget is the baseline of its child
return direction == Axis.horizontal
? child!.computeDistanceToActualBaseline(baseline)! + borderSide.width
: child!.computeDistanceToActualBaseline(baseline)! + leadingBorderSide.width;
final BaselineOffset childOffset = BaselineOffset(child?.computeDistanceToActualBaseline(baseline));
return switch (direction) {
Axis.horizontal => childOffset + borderSide.width,
Axis.vertical => childOffset + leadingBorderSide.width,
}.offset;
}

@override
Expand Down

0 comments on commit 98369bd

Please sign in to comment.