我遇到了以下错误:
======== 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问题。
编辑: 以下是一段代码以突出显示该问题:
我的主Widget通过以下方式呈现:
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
Widget组成的列表中的每个项目:
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
Widget,我就不会出现错误。
GridView
包吗? - AndrejListView.builder
一起使用,也可以与GridView.builder
一起使用。但不能与StaggeredGridView
一起使用。 虽然存在此错误,但似乎不会影响我的应用程序UI,因为我拥有所需的渲染,并且无论如何都可以正常工作...(使用StaggeredGridView.builder
) - Tom3652