垂直视口出现无界高度错误 [英] Vertical viewport was given unbounded height error

查看:14
本文介绍了垂直视口出现无界高度错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 @override
 Widget build(BuildContext context) {
   return Column(
     children: <Widget>[
       new Text("Some text"),
       ListView()
     ],
   );
 }

 Widget ListView() {
   return ListView(
     padding: EdgeInsets.symmetric(vertical: 8.0),
     children: Item(),
   );
 }

 List<Item> Item() {
   return list
     .map((item) => Item(text: item))
     .toList();
 }

 class Item extends ListTile {
   Item({String text, GestureTapCallback onTap})
    : super(subtitle: Column(children: <Widget>[
        Text(text),
      ]));
 }

屏幕上出现一个空白区域,控制台显示:

A blank space appears on the screen and the console says:

垂直视口被赋予了无限的高度.视口在滚动方向以填充其容器.

Vertical viewport was given unbounded height. Viewports expand in the scrolling direction to fill their container.

推荐答案

将 ListView 包裹在 Flexible 中就可以了.

Wrapping ListView inside Flexible will make it work.

Widget ListView() {
return new Flexible(child: new ListView(
    padding: new EdgeInsets.symmetric(vertical: 8.0),
    children: Item()));
}

这篇关于垂直视口出现无界高度错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆