首页 > 解决方案 > 如何显示适合屏幕的 Row() 儿童尺寸?

问题描述

在此处输入图像描述

如何修复不同屏幕尺寸的错误我希望如果屏幕有空间,则应该安装中间文本如果屏幕没有空间,它应该 TextOverflow.ellipsis

这是我的代码

      Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Container(
              margin: EdgeInsets.only(left: 10),
              child: Icon(
                MdiIcons.alertCircle,
                color: Colors.white,
                size: 16,
              ),
            ),
            Container(
              child: Text(
                "Your Service Request Has Been Approved",
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(
                    fontSize: 13,
                    color: Colors.white,
                    fontWeight: FontWeight.w300),
              ),
            ),
            Spacer(),
            Container(
              margin: EdgeInsets.only(right: 10),
              child: Icon(
                MdiIcons.close,
                color: Colors.white,
                size: 16,
              ),
            ),
          ],
        ),

标签: androidiosflutterflutter-layout

解决方案


您可以使用Expanded 小部件

Expanded(
 child: Text(
            "Your Service Request Has Been Approved",
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
            style: TextStyle(
                fontSize: 13,
                color: Colors.white,
                fontWeight: FontWeight.w300),
          ),
        )
)

推荐阅读