颤振中的文字换行

埃斯瓦尔·萨拉迪(Eswar Saladi)

我正在用flutter编写一个看起来像这样的项目的小部件,我是flutter的新手,我正在尝试模仿下面的卡

一张附有图片和详细信息的Flutter卡

到目前为止,这是我的小部件代码

import 'package:flutter/material.dart';
import 'package:smooth_star_rating/smooth_star_rating.dart';

class TrailCard extends StatelessWidget {
  const TrailCard({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Card(
          shape:
              RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
          child: InkWell(
            onTap: () {},
            child: Padding(
                padding: const EdgeInsets.all(16.0),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    ClipRRect(
                      borderRadius: BorderRadius.circular(20.0),
                      child: Image.asset(
                        'assets/images/cocoa.jpg',
                        height: 100,
                        width: 90,
                        fit: BoxFit.fitHeight,
                      ),
                    ),
                    Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(
                            "Boring Cocoa",
                            style: TextStyle(
                                fontSize: 18, fontWeight: FontWeight.bold),
                          ),
                          Text('Rajhamundry, AP'),
                          Text(
                            'Feel the authentic flavours of life while you visit the farms around Rajahmundry',
                            overflow: TextOverflow.ellipsis,
                          )
                        ],
                      ),
                    ),
                  ],
                )),
          )),
    );
  }
}

我尝试使用flexible和Expanded尝试使内容看起来像这样,但出现溢出错误

错误图片

Timilehin Jegede

您可以使用Padding小部件包装Flexible部件,以便仅占用所需的空间:

注意:您还应该设置Text小部件在显示省略号之前应采取的最大行数

Flexible(
      // new line
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              "Boring Cocoa",
              style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
            ),
            Text('Rajhamundry, AP'),
            Text(
              'Feel the authentic flavours of life while you visit the farms around Rajahmundry more text to cause overflow',
              // set maximum number of lines the text should take
              maxLines: 3, // new line
              overflow: TextOverflow.ellipsis,
            )
          ],
        ),
      ),
    );

结果:

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

颤振中的问题

来自分类Dev

与颤振中的堆栈对齐

来自分类Dev

颤振:在堆栈中轻拍

来自分类Dev

BottomNavigationBarItem颤振中的背景色

来自分类Dev

如何比较颤振中的时间?

来自分类Dev

颤振中的函数调用问题

来自分类Dev

颤振中的浮动动作按钮

来自分类Dev

遍历飞镖/颤振中的贴图值

来自分类Dev

颤振中的多重相关下拉

来自分类Dev

颤振中的可滚动列

来自分类Dev

在颤振中测试kIsWeb常数

来自分类Dev

颤振中的下拉按钮面临问题

来自分类Dev

了解Dart中的括号(颤振)

来自分类Dev

如何使容器在颤振中垂直居中?

来自分类Dev

颤振中的弯曲导航栏

来自分类Dev

容器中的颤振盒装饰

来自分类Dev

页面中的颤振导航栏

来自分类Dev

如何正确固定颤振中的行距

来自分类Dev

如何在颤振中管理状态?

来自分类Dev

如何在颤振中绘制扇区?

来自分类Dev

在 futureBuilder 颤振中创建 listView 的问题

来自分类Dev

颤振:颤振中的iOS样式日期选择器

来自分类Dev

是否有可能修复颤振稳定通道中“颤振”下发现的意外子“生成”

来自分类Dev

颤振中stacktrace输出中的<异步悬挂>

来自分类Dev

在颤振中的模态底部工作表中实现 WebView

来自分类Dev

空白不会从颤振中的字符串中删除

来自分类Dev

颤振\ n \ n除非硬编码字符串,否则不换行

来自分类Dev

颤振中的异步验证仍然存在问题

来自分类Dev

如何在振颤中从List <int>再现音频?