如何防止水平溢出?

时间:2019-11-21 04:30:49

标签: flutter flutter-layout

我正在努力进行这项工作,但我尝试了所有尝试,但仍然无法完成这项工作。因此,我具有以下结构:

Row(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: <Widget>[
      CircleAvatar(
        radius: 40.0,
        backgroundImage: Image
            .network(
          '$thumbnail',
          fit: BoxFit.cover,
        )
            .image,
      ),
      SizedBox(
        width: 20,
      ),
      Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(
            'Really biiiig drink name here',
            style: TextStyle(
              color: Colors.white,
              fontSize: 28
            ),
          ),
          Text(
            'Category goes here',
            style: TextStyle(
              color: Colors.white.withOpacity(.8)
            ),
          ),
        ],
      ),
    ],
  ),

它呈现如下:

overflow

如何在不为父窗口小部件定义固定宽度的情况下裁剪或包装标题文本?

3 个答案:

答案 0 :(得分:0)

Expanded添加到内部列中以为其定义宽度。

Row(
  crossAxisAlignment: CrossAxisAlignment.start,
  children: <Widget>[
    CircleAvatar(
      radius: 40.0,
      backgroundImage: Image.network(
        '$thumbnail',
        fit: BoxFit.cover,
      ).image,
    ),
    SizedBox(
      width: 20,
    ),
    Expanded(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(
            'Really biiiig drink name here',
            style: TextStyle(
              color: Colors.white,
              fontSize: 28
            ),
          ),
          Text(
            'Category goes here',
            style: TextStyle(
              color: Colors.white.withOpacity(.8)
            ),
          ),
        ],
      ),
    ),
  ],
);

答案 1 :(得分:0)

如果将扩展添加到发生溢出的位置,则应该可以解决问题。

答案 2 :(得分:0)

使用Expanded小部件来防止视图溢出

enter image description here

Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  CircleAvatar(
                    radius: 40.0,
                    backgroundImage: Image.network('https://i.stack.imgur.com/LJ30b.png', fit: BoxFit.cover,).image,
                  ),
                  SizedBox(
                    width: 20,
                  ),
                  Expanded(child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Text(
                        'Really biiiig drink name here',
                        style: TextStyle(
                            color: Colors.yellow,
                            fontSize: 28
                        ),
                      ),
                      Text(
                        'Category goes here',
                        style: TextStyle(
                            color: Colors.red.withOpacity(.8)
                        ),
                      ),
                    ],
                  ), ),

                ],
              ),