InspectorErrorBoundary class
单个检查器 Tab 的错误边界 / Per-tab error boundary
子组件在构建期抛出异常时,仅该 Tab 显示局部错误卡片(而非红色全屏), 且不会拖垮整个面板(其余 Tab、头部、标签栏均正常)。 When a child throws during build, only that tab shows a contained error card (instead of a red full-screen error), and the rest of the panel keeps working.
实现说明:Flutter 每个 Element 会在自身 performRebuild 中把“构建异常”吞掉并
替换成默认红色 ErrorWidget,因此父级无法用 try/catch 捕获子组件的构建异常。
唯一能拦截的钩子是全局的 ErrorWidget.builder。这里在边界自己的 performRebuild
期间临时替换 ErrorWidget.builder(finally 中还原),让子树内的构建异常被
渲染成该边界的错误卡片,而不影响边界外的错误展示。
Implementation note: every Flutter Element swallows its own build error and
replaces it with the default red ErrorWidget inside performRebuild, so a parent
can't catch a child's build error via try/catch. The only hook is the global
ErrorWidget.builder. We temporarily swap it for the duration of this boundary's
own rebuild (restored in finally), so build errors inside the subtree render as
this boundary's card without affecting errors elsewhere.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- InspectorErrorBoundary
Constructors
- InspectorErrorBoundary({Key? key, required Widget child, String label = 'panel'})
-
const
Properties
- child → Widget
-
被包裹的子组件 / The wrapped child
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- label → String
-
该边界的标签(用于错误卡片展示,如 Tab 名称)/ Label shown on the error card (e.g. tab name)
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
createElement(
) → InspectorErrorBoundaryElement -
Creates a StatefulElement to manage this widget's location in the tree.
override
-
createState(
) → State< InspectorErrorBoundary> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited