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

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


════════ Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderFlex#c1bcd relayoutBoundary=up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1687 pos 12: 'hasSize'
The relevant error-causing widget was
    Scaffold 
lib\pages\Cart.dart:19
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by rendering library ═════════════════════════════════
The method '>' was called on null.
Receiver: null
Tried calling: >(1e-10)
The relevant error-causing widget was
    Column 
lib\pages\Cart.dart:21
════════════════════════════════════════════════════════════════════════════════
Reloaded 2 of 568 libraries in 193ms.

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

new Column(
children: <Widget>[
 Expanded(
       child: new Container(
          child: new ListView(
            padding: EdgeInsets.only(top: 0),
            shrinkWrap: true,
            )))
]
)

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

发布了46 篇原创文章 · 获赞 8 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/yuanqi3131/article/details/103911336