Introduce debugWithActiveLayoutCleared to avoid duplicated code (#114003)
This commit is contained in:
parent
fb9065fe00
commit
e37ab48bca
@ -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
|
|||||||
String? prefixOtherLines = '',
|
String? prefixOtherLines = '',
|
||||||
DiagnosticLevel minLevel = DiagnosticLevel.debug,
|
DiagnosticLevel minLevel = DiagnosticLevel.debug,
|
||||||
}) {
|
}) {
|
||||||
RenderObject? debugPreviousActiveLayout;
|
return _withDebugActiveLayoutCleared(() => super.toStringDeep(
|
||||||
assert(() {
|
prefixLineOne: prefixLineOne,
|
||||||
debugPreviousActiveLayout = _debugActiveLayout;
|
prefixOtherLines: prefixOtherLines,
|
||||||
_debugActiveLayout = null;
|
minLevel: minLevel,
|
||||||
return true;
|
));
|
||||||
}());
|
|
||||||
final String result = super.toStringDeep(
|
|
||||||
prefixLineOne: prefixLineOne,
|
|
||||||
prefixOtherLines: prefixOtherLines,
|
|
||||||
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
|
|||||||
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user