Unverified Commit e37ab48b authored by fzyzcjy's avatar fzyzcjy Committed by GitHub

Introduce debugWithActiveLayoutCleared to avoid duplicated code (#114003)

parent fb9065fe
...@@ -1591,6 +1591,26 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im ...@@ -1591,6 +1591,26 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im
static RenderObject? get debugActiveLayout => _debugActiveLayout; static RenderObject? get debugActiveLayout => _debugActiveLayout;
static RenderObject? _debugActiveLayout; static RenderObject? _debugActiveLayout;
/// Set [debugActiveLayout] to null when [inner] callback is called.
/// This is useful when you have to temporarily clear that variable to
/// disable some false-positive checks, such as when computing toStringDeep
/// or using custom trees.
@pragma('vm:prefer-inline')
static T _withDebugActiveLayoutCleared<T>(T Function() inner) {
RenderObject? debugPreviousActiveLayout;
assert(() {
debugPreviousActiveLayout = _debugActiveLayout;
_debugActiveLayout = null;
return true;
}());
final T result = inner();
assert(() {
_debugActiveLayout = debugPreviousActiveLayout;
return true;
}());
return result;
}
/// Whether the parent render object is permitted to use this render object's /// Whether the parent render object is permitted to use this render object's
/// size. /// size.
/// ///
...@@ -3399,22 +3419,11 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im ...@@ -3399,22 +3419,11 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im
String? prefixOtherLines = '', String? prefixOtherLines = '',
DiagnosticLevel minLevel = DiagnosticLevel.debug, DiagnosticLevel minLevel = DiagnosticLevel.debug,
}) { }) {
RenderObject? debugPreviousActiveLayout; return _withDebugActiveLayoutCleared(() => super.toStringDeep(
assert(() {
debugPreviousActiveLayout = _debugActiveLayout;
_debugActiveLayout = null;
return true;
}());
final String result = super.toStringDeep(
prefixLineOne: prefixLineOne, prefixLineOne: prefixLineOne,
prefixOtherLines: prefixOtherLines, prefixOtherLines: prefixOtherLines,
minLevel: minLevel, minLevel: minLevel,
); ));
assert(() {
_debugActiveLayout = debugPreviousActiveLayout;
return true;
}());
return result;
} }
/// Returns a one-line detailed description of the render object. /// Returns a one-line detailed description of the render object.
...@@ -3427,18 +3436,7 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im ...@@ -3427,18 +3436,7 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im
String joiner = ', ', String joiner = ', ',
DiagnosticLevel minLevel = DiagnosticLevel.debug, DiagnosticLevel minLevel = DiagnosticLevel.debug,
}) { }) {
RenderObject? debugPreviousActiveLayout; return _withDebugActiveLayoutCleared(() => super.toStringShallow(joiner: joiner, minLevel: minLevel));
assert(() {
debugPreviousActiveLayout = _debugActiveLayout;
_debugActiveLayout = null;
return true;
}());
final String result = super.toStringShallow(joiner: joiner, minLevel: minLevel);
assert(() {
_debugActiveLayout = debugPreviousActiveLayout;
return true;
}());
return result;
} }
@protected @protected
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment