flutter - RenderCustomMultiChildLayoutBox 的每个 child 都必须在其父数据中有一个 ID

标签 flutter error-handling

我正在尝试用我自己的屏幕(加载屏幕)替换 flutter 的红屏。但是应用程序在触发时崩溃。这是我更换屏幕的方法

ErrorWidget.builder = (FlutterErrorDetails details) => Scaffold(
    appBar: AppBar(
      title: Text("Loading"),
    ),
    body: Positioned(
      child:Loading()
    ),

  );
加载小部件是
Container(
      child: Center(
         child: SpinKitFadingCube(
            color: Colors.white,
            size: 50.0,
          )
      ),
      color: Colors.white.withOpacity(0.8),
    );
堆栈跟踪是
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4952 pos 16: 'child is! ParentDataElement<ParentData>': is not true.
The relevant error-causing widget was: 
  Scaffold file:///C:/Users/Hemant/AndroidStudioProjects/discountapp/lib/main.dart:10:58
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
Incorrect use of ParentDataWidget.
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
Incorrect use of ParentDataWidget.
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by rendering library ═════════════════════════════════════════════════════
Every child of a RenderCustomMultiChildLayoutBox must have an ID in its parent data.
The relevant error-causing widget was: 
  Scaffold file:///C:/Users/Hemant/AndroidStudioProjects/discountapp/lib/main.dart:10:58
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by rendering library ═════════════════════════════════════════════════════
The following assertion was thrown during performLayout():
Every child of a RenderCustomMultiChildLayoutBox must have an ID in its parent data.

The following child has no ID: _RenderColoredBox#1154c NEEDS-LAYOUT NEEDS-PAINT
...  needs compositing
...  parentData: offset=Offset(0.0, 0.0); id=null
...  constraints: MISSING
...  size: MISSING
...  behavior: opaque
The relevant error-causing widget was: 
  Scaffold file:///C:/Users/Hemant/AndroidStudioProjects/discountapp/lib/main.dart:10:58
When the exception was thrown, this was the stack: 
#0      MultiChildLayoutDelegate._callPerformLayout.<anonymous closure> (package:flutter/src/rendering/custom_layout.dart:228:13)
#1      MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:234:10)
#2      RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:401:14)
#3      RenderObject.layout (package:flutter/src/rendering/object.dart:1776:7)
#4      RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
...
The following RenderObject was being processed when the exception was fired: RenderCustomMultiChildLayoutBox#ea7eb relayoutBoundary=up6
...  needs compositing
...  parentData: <none> (can use size)
...  constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=646.8)
...  size: Size(392.7, 646.8)
RenderObject: RenderCustomMultiChildLayoutBox#ea7eb relayoutBoundary=up6
  needs compositing
  parentData: <none> (can use size)
  constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=646.8)
  size: Size(392.7, 646.8)
...  child 1: _RenderColoredBox#1154c NEEDS-LAYOUT NEEDS-PAINT
...    needs compositing
...    parentData: offset=Offset(0.0, 0.0); id=null
...    constraints: MISSING
...    size: MISSING
...    behavior: opaque
...    child: RenderPositionedBox#4cf2c NEEDS-LAYOUT NEEDS-PAINT
...      needs compositing
...      parentData: <none>
...      constraints: MISSING
...      size: MISSING
...      alignment: center
...      textDirection: ltr
...      widthFactor: expand
...      heightFactor: expand
...      child: RenderPositionedBox#79ddb NEEDS-LAYOUT NEEDS-PAINT
...        needs compositing
...        parentData: offset=Offset(0.0, 0.0)
...        constraints: MISSING
...        size: MISSING
...        alignment: center
...        textDirection: ltr
...        widthFactor: expand
...        heightFactor: expand
...        child: RenderConstrainedBox#ba168 NEEDS-LAYOUT NEEDS-PAINT
...          needs compositing
...          parentData: offset=Offset(0.0, 0.0)
...          constraints: MISSING
...          size: MISSING
...          additionalConstraints: BoxConstraints(w=50.0, h=50.0)
...  child 2: RenderConstrainedBox#26ec0 NEEDS-LAYOUT NEEDS-PAINT
...    needs compositing
...    parentData: offset=Offset(0.0, 0.0); id=_ScaffoldSlot.appBar
...    constraints: MISSING
...    size: MISSING
...    additionalConstraints: BoxConstraints(0.0<=w<=Infinity, 0.0<=h<=56.0)
...    child: RenderSemanticsAnnotations#95f4f NEEDS-LAYOUT NEEDS-PAINT
...      needs compositing
...      parentData: <none>
...      constraints: MISSING
...      semantic boundary
...      size: MISSING
...      child: RenderAnnotatedRegion<SystemUiOverlayStyle>#5aedc NEEDS-LAYOUT NEEDS-PAINT
...        needs compositing
...        parentData: <none>
...        constraints: MISSING
...        size: MISSING
...        child: RenderPhysicalModel#177a3 NEEDS-LAYOUT NEEDS-PAINT
...          needs compositing
...          parentData: <none>
...          constraints: MISSING
...          size: MISSING
...          elevation: 4.0
...          color: MaterialColor(primary value: Color(0xff2196f3))
...          shadowColor: MaterialColor(primary value: Color(0xff2196f3))
...          shape: BoxShape.rectangle
...          borderRadius: BorderRadius.zero
...  child 3: RenderStack#c7c1d NEEDS-LAYOUT NEEDS-PAINT
...    parentData: offset=Offset(0.0, 0.0); id=_ScaffoldSlot.floatingActionButton
...    constraints: MISSING
...    size: MISSING
...    alignment: centerRight
...    textDirection: ltr
...    fit: loose
...    child 1: RenderTransform#9b142 NEEDS-LAYOUT NEEDS-PAINT
...      parentData: not positioned; offset=Offset(0.0, 0.0)
...      constraints: MISSING
...      size: MISSING
...      transform matrix: [0] 0.0,0.0,0.0,0.0
[1] 0.0,0.0,0.0,0.0
[2] 0.0,0.0,1.0,0.0
[3] 0.0,0.0,0.0,1.0
...      origin: null
...      alignment: center
...      textDirection: ltr
...      transformHitTests: true
...      child: RenderTransform#9f5b2 NEEDS-LAYOUT NEEDS-PAINT
...        parentData: <none>
...        constraints: MISSING
...        size: MISSING
...        transform matrix: [0] 0.7,0.7,0.0,0.0
[1] -0.7,0.7,0.0,0.0
[2] 0.0,0.0,1.0,0.0
[3] 0.0,0.0,0.0,1.0
...        origin: null
...        alignment: center
...        textDirection: ltr
...        transformHitTests: true
════════════════════════════════════════════════════════════════════════════════════════════════════
W/libEGL  (22033): EGLNativeWindowType 0x7019d6f010 disconnect failed
我尝试用简单的文本小部件替换加载屏幕。同样的事情发生。我从另一个 stackoverflow 帖子中发现了如何做到这一点。任何帮助将不胜感激

最佳答案

可以尝试的东西,

  • 用堆栈包裹 Positioned() 小部件。
  • 为容器提供宽度和高度约束
  •       Stack(
            children: [
              Positioned(top:  10,child: Loading(.....))
            ],
          ),
    
    不知道为什么你需要定位 Widget 但是,上面是要走的路。
    Container(
           height: MediaQuery.of(context).size.height,
           width: MediaQuery.of(context).size.width,
      child: Center(
         child: SpinKitFadingCube(
            color: Colors.white,
            size: 50.0,
          )
      ),
      color: Colors.white.withOpacity(0.8),
    );
    
    这就是你应该如何约束它(示例)。

    关于flutter - RenderCustomMultiChildLayoutBox 的每个 child 都必须在其父数据中有一个 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63068383/

    相关文章:

    flutter - image_picker : ^0. 7.2+1 使应用程序崩溃

    c - 使用 'goto' 的流量控制宏

    c++ - 在没有循环/条件的情况下将字符串检查为 int 错误

    error-handling - NetLogo 5.3.1,错误消息 “Expected [”

    python - '> =' not supported between instances of ' NoneType'和 'float'

    flutter - 如何解决flutter中的PermissionHandler错误?

    flutter - 如何将继承的小部件传递给整个 Material 应用程序

    dart - 如何在flutter中截取屏幕外的小部件截图?

    flutter - 取消键盘焦点在按下的多个按钮上

    python - 使用 Google App Engine 上的 Django 将错误记录到数据库