我正在尝试在我的应用程序中使用gridview。但是每当我将gridview的padding更改为20.0时,都会引发异常:
Another exception was thrown: SliverGeometry is not valid: The "maxPaintExtent" is less than the "paintExtent".
这是异常的详细版本:
I/flutter (18662): The following assertion was thrown during performLayout():
I/flutter (18662): SliverGeometry is not valid: The "maxPaintExtent" is less than the "paintExtent".
I/flutter (18662): The maxPaintExtent is 239.28571428571428, but the paintExtent is 239.2857142857143. Maybe you have
I/flutter (18662): fallen prey to floating point rounding errors, and should explicitly apply the min() or max()
I/flutter (18662): functions, or the clamp() method, to the paintExtent? By definition, a sliver can't paint more than
I/flutter (18662): the maximum that it can paint!
I/flutter (18662): The RenderSliver that returned the offending geometry was:
I/flutter (18662): RenderSliverGrid#80894 relayoutBoundary=up2 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (18662): creator: SliverGrid ← SliverPadding ← Viewport ← _ScrollableScope ←
I/flutter (18662): IgnorePointer-[GlobalKey#12cb3] ← Semantics ← Listener ← _GestureSemantics ←
I/flutter (18662): RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#74675] ←
I/flutter (18662): _ScrollSemantics-[GlobalKey#bd1a3] ← RepaintBoundary ← CustomPaint ← ⋯
I/flutter (18662): parentData: paintOffset=Offset(80.0, 80.0) (can use size)
I/flutter (18662): constraints: SliverConstraints(AxisDirection.down, GrowthDirection.forward, ScrollDirection.idle,
I/flutter (18662): scrollOffset: 0.0, remainingPaintExtent: 310.0, crossAxisExtent: 280.0, crossAxisDirection:
I/flutter (18662): AxisDirection.right, viewportMainAxisExtent: 330.0, remainingCacheExtent: 560.0 cacheOrigin: 0.0 )
I/flutter (18662): geometry: SliverGeometry(scrollExtent: 239.3, paintExtent: 239.3, maxPaintExtent: 239.3,
I/flutter (18662): hasVisualOverflow: true, cacheExtent: 239.3)
I/flutter (18662): currently live children: 0 to 39
这是我的代码:
return new Container(
child: new SafeArea(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new Container(
color: Colors.red[900],
child: new SizedBox(
width: MediaQuery.of(context).size.width,
height: 158.0,
child: new Center(
child: new Text('Hello World', style: new TextStyle(fontFamily: 'RobotoCondensed', fontSize: 25.0, color: Colors.white))
)
)
),
new Expanded(
child: new GridView.count(
padding: new EdgeInsets.all(20.0),
mainAxisSpacing: 5.0,
crossAxisSpacing: 5.0,
crossAxisCount: 7,
children: List.generate(40, (index){
return new Container(
color: Colors.pink[300],
);
}
)
) //GridView
),
]
),
)
);
但是当我将gridview填充更改为50.0或80.0时,它不会引发异常。
我已经看到一些与this相关的错误。
该异常表明,也许我已成为浮点数舍入错误的牺牲品,应该将min()或max()函数或钳位()方法显式应用于paintExtent。
但是我应该在哪里找到这个paintExtent变量?我在GridView.count中找不到它。
我将不胜感激。