flutter错误之 The method '>' was called on null

怼烎@ 2023-06-28 15:28 127阅读 0赞

如下方的报错,一般是ListView搭配Column或者Row出错了,看我下面的错误是Column

  1. ════════ Exception caught by rendering library ═════════════════════════════════
  2. RenderBox was not laid out: RenderFlex#c1bcd relayoutBoundary=up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
  3. 'package:flutter/src/rendering/box.dart':
  4. Failed assertion: line 1687 pos 12: 'hasSize'
  5. The relevant error-causing widget was
  6. Scaffold
  7. lib\pages\Cart.dart:19
  8. ════════════════════════════════════════════════════════════════════════════════
  9. ════════ Exception caught by rendering library ═════════════════════════════════
  10. The method '>' was called on null.
  11. Receiver: null
  12. Tried calling: >(1e-10)
  13. The relevant error-causing widget was
  14. Column
  15. lib\pages\Cart.dart:21
  16. ════════════════════════════════════════════════════════════════════════════════
  17. Reloaded 2 of 568 libraries in 193ms.

在这里插入图片描述
还有一种错误是Row:
在这里插入图片描述
解决方法:把包含在Column下的ListView容器放在Expand就可以了,然后 在ListView中加入shrinkWrap: true就可以了,Row 同理

  1. new Column(
  2. children: <Widget>[
  3. Expanded(
  4. child: new Container(
  5. child: new ListView(
  6. padding: EdgeInsets.only(top: 0),
  7. shrinkWrap: true,
  8. )))
  9. ]
  10. )

成功解决:
在这里插入图片描述

发表评论

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

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

相关阅读