我正在设计一张卡片的样式,里面有这些多个图标元素和文字.我在安排行和列以解决此问题时遇到问题;

Image 1

这就是我想要实现的;

Image 2

这是我给我问题的那一行的代码;

Row(
                  children: [
                    ClipRect(
                      child: Container(
                        height: 11,
                        width: 11,
                        child: Image.asset('assets/info.png'),
                      ),
                    ),
                    Container(
                      height: 48,
                      child: Column(
                        children: [
                          Text(
                            "Now that you've finished a plan, it's essential to measure your growth. We've included assessments and activities to do just that.",
                            style: GoogleFonts.poppins(
                              textStyle: TextStyle(
                                color: Color(0x80484848),
                                fontWeight: FontWeight.w400,
                                fontSize: 8,
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),

我认为如果文本适合列,那么它总是正确对齐的.我希望溢出的文本转到下一行.

推荐答案

EDIT:要使文本换行到下一行,请用Expanded():

Row(
          children: [
            ClipRect(
              child: Container(
                height: 11,
                width: 11,
                child: Image.asset('assets/info.png'),
              ),
            ),
            Expanded(
              child: Column(
                children: [
                  Text(
                    "Now that you've finished a plan, it's essential to measure your growth. We've included assessments and activities to do just that.",
                    style: TextStyle(
                      overflow: TextOverflow.visible,
                      color: Color(0x80484848),
                      fontWeight: FontWeight.w400,
                      fontSize: 30,
                    ),
                  ),
                ],
              ),
            ),
          ],
        )

为了避免溢出,用Flexible()包裹Container(),用FittedBox()包裹Text().

FittedBox()上的文档:

根据适合度在其内部zoom 和定位子对象.

因此,fittedBox将相应地调整字体大小.

您的代码应该如下所示:

Row(
          children: [
            ClipRect(
              child: Container(
                height: 11,
                width: 11,
                child: Image.asset(
                    'assets/info.png'),
              ),
            ),
            Flexible(
              child: Container(
                height: 48,
                child: Column(
                  children: [
                    FittedBox(
                      child: Text(
                        "Now that you've finished a plan, it's essential to measure your growth. We've included assessments and activities to do just that.",
                        style: TextStyle(
                          color: Color(0x80484848),
                          fontWeight: FontWeight.w400,
                          fontSize: 30,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        )

结果(注意文本大小比例):

enter image description here


或者,您也可以使用TextOverflow而不是FittedBox(),这将在溢出文本中添加省略号(...):

 Row(
          children: [
            ClipRect(
              child: Container(
                height: 11,
                width: 11,
                child: Image.asset(
                    'assets/info.png'),
              ),
            ),
            Flexible(
              child: Container(
                height: 48,
                child: Column(
                  children: [
                    Text(
                      "Now that you've finished a plan, it's essential to measure your growth. We've included assessments and activities to do just that.",
                      style: TextStyle(
                        overflow: TextOverflow.ellipsis,
                        color: Color(0x80484848),
                        fontWeight: FontWeight.w400,
                        fontSize: 30,
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        )

结果(注意省略号):

enter image description here

Ios相关问答推荐

使用CGAffineTransform旋转视图只起作用一次吗?

如何在SwiftUI中基于嵌套视图中的状态动态显示外部视图的内容?

如何为 Firebase Auth 实施 Firebase AppCheck?

创建方案时运行 pod install 时出错

创建 Flutter 项目时,如何从我的系统中删除特定的开发者身份?

Apple Metal iOS 为什么 GLKMatrix4MakeLookAt 来回摇摆

由于缺少 libarclite_iphonesimulator.a 文件,将 XCode 升级到 14.3 后无法在模拟器上运行 Flutter 应用程序

Task.cancel() 的 TaskPriority 的区别

Flutter IOS 构建错误 - 在签名和功能编辑器中 Select 一个开发团队.

渲染的海边重定向在物理 iOS 设备上不起作用

转换在 NavigationView 中不起作用

SwiftUI 我自己的渲染函数的返回类型是什么?

滑动以返回特定的 SwiftUI 视图

在 Swift 中上传带参数的图像

如何使用 Contacts Framework 获取 iOS 9 中的所有联系人记录

以编程方式 Select UITextField 中的所有文本

swift 语言中的 null / nil

iOS 7 及更高版本: for each 视图控制器设置状态栏样式

从故事板导航到其他 Swift 1.2 文件时 Xcode 6.3 崩溃

使用 Xcode 的 All Exceptions 断点时忽略某些异常