颤振:ConstrainedBox的子级不显示

时间:2018-12-18 10:17:44

标签: flutter

当我将BoxConstraints的maxHeight设置为100或其他值时,可以显示图像。但是,当我将maxHeight设置为0时,图像不可见。如何使其可见?

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: Center(
      child: ConstrainedBox(
        constraints: BoxConstraints(maxHeight: 0),
        child: Row(
          children: <Widget>[
            Text('world'),
            IconButton(icon: Icon(Icons.ac_unit),),
            Image.network(
                'http://cdn.nanxiongnandi.com/bing/KingfishersTaipei_ZH-CN13235647615_1366x768.jpg'),
          ],
        ),
      ),
    ),
  );
}

result

1 个答案:

答案 0 :(得分:0)

我发现您的图片无法加载。检查以下代码,将maxHeight设置为100。

 return Scaffold(
  body: Center(
    child: ConstrainedBox(
      constraints: BoxConstraints(maxHeight: 100),
      child: Row(
        children: <Widget>[
          Text('world'),
          IconButton(
            icon: Icon(Icons.ac_unit),
          ),
          Image.network(
              'https://raw.githubusercontent.com/flutter/website/master/src/_includes/code/layout/lakes/images/lake.jpg'),
        ],
      ),
    ),
  ),
);

enter image description here