【问题标题】:Dynamically spread text to multiple lines according to their length in flutter根据 Flutter 中的长度将文本动态分布到多行
【发布时间】:2021-08-25 03:46:54
【问题描述】:

所以,我在颤振中构建这个应用程序,用户最多可以评论 150 个字符,当我试图显示它时,由于字符串的长度,会出现这个渲染溢出错误。那么,如何根据文本的长度将文本分散到多行并相应地显示它们。这里有一个类似的问题,但这并不能解决我的问题。我能得到一些帮助吗?

Container(
                alignment: Alignment.center,
                width: double.infinity,
                height: 100.0,
                child: Row(
                  children: [
                    Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: ClipOval(
                        child: Image.asset(
                          'assets/images/c1.png',
                          fit: BoxFit.cover,
                          width: 69,
                          height: 69,
                        ),
                      ),
                    ),
                    Column(
                      // mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        const Text(
                          '@username',
                          style: TextStyle(color: Colors.white),
                        ),
                        Expanded(child: const Text('fwegergwefrvgervuhygtfvrcdxddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddne, a very long comment!!!', 
                        textAlign: TextAlign.justify,
                        maxLines: 6,
 overflow: TextOverflow.ellipsis,)),
                      ],
                    ),
                  ],
                ),
              ),

【问题讨论】:

    标签: android flutter dart flutter-layout cross-platform


    【解决方案1】:

    Expanded 小部件包装Column

    Container(
            alignment: Alignment.center,
            width: double.infinity,
            height: 100.0,
            child: Row(
              children: [
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: ClipOval(
                    child: Image.asset(
                      'assets/images/c1.png',
                      fit: BoxFit.cover,
                      width: 69,
                      height: 69,
                    ),
                  ),
                ),
                Expanded(
                  child: Column(
                    children: [
                      const Text(
                        '@username',
                        style: TextStyle(color: Colors.white),
                      ),
                      Expanded(
                          child: const Text(
                        'fwegergwefrvgervuhygtfvrcdxddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddne, a very long comment!!!',
                        textAlign: TextAlign.justify,
                        maxLines: 6,
                        overflow: TextOverflow.ellipsis,
                      )),
                    ],
                  ),
                ),
              ],
            ),
          )
    

    【讨论】:

      猜你喜欢
      • 2018-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-02
      • 2019-03-09
      • 2014-11-06
      • 2021-07-18
      相关资源
      最近更新 更多