我有以下错误:
======== Exception caught by scheduler library =====================================================
The following assertion was thrown during a scheduler callback:
Updated layout information required for RenderIndexedSemantics#f51aa NEEDS-LAYOUT to calculate semantics.
'package:flutter/src/rendering/object.dart':
Failed assertion: line 2658 pos 12: '!_needsLayout'
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.md
When the exception was thrown, this was the stack:
#2 RenderObject._getSemanticsForParent (package:flutter/src/rendering/object.dart:2658:12)
#3 RenderObject._getSemanticsForParent.<anonymous closure> (package:flutter/src/rendering/object.dart:2680:61)
#4 Iterable.forEach (dart:core/iterable.dart:257:30)
#5 RenderSliverVariableSizeBoxAdaptor.visitChildren (package:flutter_staggered_grid_view/src/rendering/sliver_variable_size_box_adaptor.dart:296:29)
#6 RenderObject.visitChildrenForSemantics (package:flutter/src/rendering/object.dart:2765:5)
...
====================================================================================================
我想知道这是什么意思,通常什么时候发生?
我正在使用flutter_staggered_grid_view: ^0.4.0
包。
如果需要,我将创建一个 GitHub 问题。
编辑:这是一段突出问题的代码:
我的主要小部件由以下人员呈现:
StaggeredGridView.countBuilder(
itemBuilder: (BuildContext context, int index) {
return MyCustomItem();
},
padding: EdgeInsets.only(left: Constants.maxWidth*2/100, right: Constants.maxWidth*2/100,
bottom: Constants.maxHeight*10/100 + 65), // home button size + margin bottom
crossAxisCount: 2,
mainAxisSpacing: 20,
crossAxisSpacing: Constants.maxWidth*2/100,
itemCount: 30,
physics: BouncingScrollPhysics(),
staggeredTileBuilder: (int index) {
return StaggeredTile.fit(1);
},
),
和MyCustomItem
组成 List 的每个项目的小部件:
Column(
children: [
GestureDetector(
child:
Container(
margin: (widget.index == 0 || widget.index == 1) ? EdgeInsets.only(top: Constants.maxHeight*6/100+60) : EdgeInsets.all(0),
//width: postWidth,
// TODO : post height
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(20)),
child: Image.asset("assets/images/test.jpg"), // TODO
),
),
onTap: () {
// TODO
},
onDoubleTap: () {
// TODO
},
),
Row(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
GestureDetector(child:
Container(
margin: EdgeInsets.only(top: 10, bottom: 3),
width: 35,
height: 35,
),
onTap: () {
// TODO
},
),
Flexible(child:
Container(
width: Constants.maxWidth*25/100,
child:
Text(
"tessssst",
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Color(resColors.getShadow()),
),
maxLines: 1,
),
),
),
],
),
Spacer(),
Container(
margin: EdgeInsets.only(right: Constants.maxWidth * 2 / 100),
child: Column(children: [
Container(
margin: EdgeInsets.only(bottom: 3, top: 10),
child: InkWell(
onTap: () {
// TODO
},
highlightColor: Colors.transparent,
splashColor: Colors.transparent,
),
),
Text("1029"),
]),
),
Container(
child: Column(children: [
Container(
margin: EdgeInsets.only(bottom: 3, top: 10, right: Constants.maxWidth/100),
child: InkWell(
onTap: () => {},// TODO
highlightColor: Colors.transparent,
splashColor: Colors.transparent,
),
),
Text("Test"),
]),
),
],
)
],
);
我要补充一点,如果MyCustomItem
只是一个Text
小部件,我没有错误。