解决RenderUiKitView object was given an infinite size during layout.

比眉伴天荒 2022-11-10 10:43 80阅读 0赞

场景

有个需求,需要在Column中放个Webview。

  1. Column(
  2. children: [
  3. Text(....),
  4. Text(....),
  5. Webview(
  6. .....
  7. )
  8. ]
  9. )

运行后控制台显示以下错误

  1. ════════ Exception caught by rendering library ═════════════════════════════════════════════════════
  2. The following assertion was thrown during performLayout():
  3. RenderUiKitView object was given an infinite size during layout.
  4. This probably means that it is a render object that tries to be as big as possible, but it was put inside another render object that allows its children to pick their own size.
  5. The nearest ancestor providing an unbounded height constraint is: RenderFlex#dbb0a relayoutBoundary=up2 NEEDS-LAYOUT NEEDS-COMPOSITING-BITS-UPDATE OVERFLOWING
  6. ... parentData: offset=Offset(30.0, 0.0) (can use size)
  7. ... constraints: BoxConstraints(0.0<=w<=354.0, 0.0<=h<=840.0)
  8. ... size: Size(354.0, 840.0)
  9. ... direction: vertical
  10. ... mainAxisAlignment: start
  11. ... mainAxisSize: max
  12. ... crossAxisAlignment: center
  13. ... verticalDirection: down
  14. The constraints that applied to the RenderUiKitView were: BoxConstraints(0.0<=w<=354.0, 0.0<=h<=Infinity)
  15. The exact size it was given was: Size(354.0, Infinity)
  16. See https://flutter.dev/docs/development/ui/layout/box-constraints for more information.

解决方法

根据错误信息描述,原因是在渲染控件时,Webview是无限大的,在Column中是不允许这样的。我们只需要使用Expanded将其包裹即可。

  1. Column(
  2. children: [
  3. Text(....),
  4. Text(....),
  5. Expanded(
  6. child: Webview(
  7. ......
  8. )
  9. )
  10. ]
  11. )

发表评论

表情:
评论列表 (有 0 条评论,80人围观)

还没有评论,来说两句吧...

相关阅读