flutter - 如果溢出,Flutter ListView 文本会显示在多行上
问题描述
我有一个列表视图,其中我有另一个列表视图以水平显示简单文本,但问题是它在左侧溢出如果我给列表视图提供宽度,它将滚动列表。我想如果它溢出那么它会简单地转到下一行而不是溢出或滚动。
我的代码
Expanded(
child: new ListView.builder(
itemCount: respondedData3['data'].length,
shrinkWrap: true,
scrollDirection: Axis.vertical,
physics: ScrollPhysics(),
itemBuilder: (context, index) {
String TimeFormat = DateFormat("yyyy-MM-dd").format(DateTime.parse(respondedData3['data'][index]['appointmentDate']));
return Padding(
padding: const EdgeInsets.only(left: 15, right: 15),
child: Container(
child: GestureDetector(
onTap: () async {
Navigator.pop(context);
},
// onTap: widget.onPressed,
child: Stack(children: [
Container(
height: 80,
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Column(
children: [
Text(TimeFormat, style: TextStyle(fontSize: 14, fontFamily: 'SegoeUI-Bold', color: kPrimaryColor)),
Text(respondedData3['data'][index]['appointmentTime'].toString(), style: TextStyle(fontSize: 13, fontFamily: 'SegoeUI', color: textGreyColor))
],
),
SizedBox(
width: 10,
),
Container(
color: Colors.grey,
height: 40,
width: 1.5,
),
SizedBox(
width: 10,
),
Column(
children: [
Text(respondedData3['data'][index]['serviceProviderName'].toString(), style: TextStyle(fontSize: 13, fontFamily: 'SegoeUI-Bold', color: textGreyColor)),
Container(
height: 20.0,
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: serviceShow.length,
itemBuilder: (BuildContext context, int index) => Text('${serviceShow[index]["Name"]} ${serviceShow[index]["Time"]} ${serviceShow[index]["Price"]}'),
),
),
],
)
],
),
],
),
),
]),
),
),
);
},
),
)
您可以在图像中看到它显示溢出错误,我需要在第二行中显示它。
解决方案
在您的文本上添加最大行数
Text(
'Your multiline text',
maxLines: 2, //2 or more line you want
overflow: TextOverflow.ellipsis,
),
),
推荐阅读
- node.js - UnhandledPromiseRejectionWarning: TypeError: this.second() 不是函数
- python-3.x - 使用分隔符连接 Pandas Dataframe 中的列
- flutter - 如何将内存中的密码清零。Flutter 保留来自 TextEditingController 的所有输入
- sql - MongoDB SQL 查询在 sql-to-mongo-db-query-converter 中具有连字符 (-) 的表/集合
- spring-boot - 使用 GitHub 操作的 Azure 应用服务错误:条目标头无效
- apache - 根据页面名称重写 URL
- python - 如果它们最初或交换后的位置在 Pandas 中相同,则将重复的行删除多列
- c# - 如何将整数值添加到日期并在c#中计算结束日期
- c# - 在 Blazor 页面的 OnInitializedAsync() 中访问 context.User
- reactjs - 如何使用类组件中的 react-router 链接从传递数据的组件中使用数据?