[go: nahoru, domu]

Skip to content

Commit

Permalink
Clear the static _debugDoingBaseline flag if baseline calculation thr…
Browse files Browse the repository at this point in the history
…ows (#110387)
  • Loading branch information
jason-simmons committed Aug 30, 2022
1 parent 728bd65 commit f57fcac
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/flutter/lib/src/rendering/box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2191,8 +2191,12 @@ abstract class RenderBox extends RenderObject {
return false;
}());
assert(_debugSetDoingBaseline(true));
final double? result = getDistanceToActualBaseline(baseline);
assert(_debugSetDoingBaseline(false));
final double? result;
try {
result = getDistanceToActualBaseline(baseline);
} finally {
assert(_debugSetDoingBaseline(false));
}
if (result == null && !onlyReal) {
return size.height;
}
Expand Down
33 changes: 33 additions & 0 deletions packages/flutter/test/rendering/box_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ class MissingSetSizeRenderBox extends RenderBox {
void performLayout() { }
}

class BadBaselineRenderBox extends RenderBox {
@override
void performLayout() {
size = constraints.biggest;
}

@override
double? computeDistanceToActualBaseline(TextBaseline baseline) {
throw Exception();
}
}

void main() {
TestRenderingFlutterBinding.ensureInitialized();

Expand Down Expand Up @@ -1196,6 +1208,27 @@ void main() {
),
);
});

test('debugDoingBaseline flag is cleared after exception', () {
final BadBaselineRenderBox badChild = BadBaselineRenderBox();
final RenderBox badRoot = RenderBaseline(
child: badChild,
baseline: 0.0,
baselineType: TextBaseline.alphabetic,
);
final List<dynamic> exceptions = <dynamic>[];
layout(badRoot, onErrors: () {
exceptions.addAll(TestRenderingFlutterBinding.instance.takeAllFlutterExceptions());
});
expect(exceptions, isNotEmpty);

final RenderBox goodRoot = RenderBaseline(
child: RenderDecoratedBox(decoration: const BoxDecoration()),
baseline: 0.0,
baselineType: TextBaseline.alphabetic,
);
layout(goodRoot, onErrors: () { assert(false); });
});
}

class _DummyHitTestTarget implements HitTestTarget {
Expand Down

0 comments on commit f57fcac

Please sign in to comment.