首页 > 解决方案 > 带有 2 个子图标和(扩展)文本(长)的行,它们之间有空格

问题描述

我有一排有 2 个孩子的一排图标(位置)和文本

这是示例图像在此处输入图像描述

              Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Icon(
                      Icons.location_on,
                      color: Colors.white,
                    ),
                    Expanded(
                      child: Text(
                        "Kyla Olsen Ap #651-8679 Sodales Av.Tamuning PA 10855 (492) 709-6392", //  a long address
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            color: Colors.white,
                            fontSize: 16,
                            fontWeight: FontWeight.bold),
                      ),
                    ),
                  ],
                ),

这在图标和文本之间有一些空间。如果我对齐文本开始,则它没有空格,但第二行也从开始,我希望文本居中

我希望位置 iocn 和文本没有任何空间,例如电话号码或电子邮件地址。

标签: flutterflutter-row

解决方案


快速修复,将您的扩展小部件更改为将文本包装为灵活小部件,如下所示:

Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Icon(
                      Icons.location_on,
                      color: Colors.white,
                    ),
                    Flexible(
                      child: Text(
                        "Kyla Olsen Ap #651-8679 Sodales Av.Tamuning PA 10855 (492) 709-6392", //  a long address
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            color: Colors.white,
                            fontSize: 16,
                            fontWeight: FontWeight.bold),
                      ),
                    ),
                  ],
                ),

推荐阅读