我正在尝试用自己的屏幕(正在加载的屏幕)替换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
我尝试用一个简单的Text Widget替换加载屏幕。同样的事情发生。我从另一个stackoverflow帖子中找到了如何执行此操作。任何帮助将不胜感激
答案 0 :(得分:0)
您可以尝试的事情
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),
);
这就是约束它的方式(示例)。