[英]How to call an index in Flutter onTap, using ListTile in a for loop
[英]How to handle right overflowed inside ListTile flutter
我有 listTile 來顯示標題和副標題......這是代碼
ListTile(
leading: InkWell(
onTap: () {},
child: Icon(Icons.fingerprint),
),
title: Text("name xxx"),
subtitle:
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
"xxxxxxxx",
),
Text(
' - ',
style: TextStyle(
fontSize: 10.0,
),
),
Text(
"yyyyyyyyyy",
style: TextStyle(
fontSize: 10.0,
),
),
],
),
],
),
trailing: ...
)
當right overflowed by 69 pixels
用長句替換xxxxxx
和yyyyyyy
...
你的問題有很多潛在的解決方案,我可以建議你兩個簡單的選擇:
如果您絕對需要顯示兩個 Text 小部件的所有內容,則可以將它們包裝在Wrap
中,而不是Row
中:
ListTile(
leading: InkWell(
onTap: () {},
child: Icon(Icons.fingerprint),
),
title: Text("name xxx"),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Wrap(
children: [
Text(
"long text yeah long text long long and very long",
),
Text(
' - ',
style: TextStyle(
fontSize: 10.0,
),
),
Text(
"Another quite long stuff, it's veeery long and by no means short",
style: TextStyle(
fontSize: 10.0,
),
),
],
),
],
),
),
如果您需要您的 Row 及其所有子項保持在一行文本中,您可以使用Flexible
包裝您的 Text 小部件並指示它們處理潛在的溢出(可能使用省略號):
ListTile(
leading: InkWell(
onTap: () {},
child: Icon(Icons.fingerprint),
),
title: Text("name xxx"),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Flexible(
child: Text(
"long text yeah long text long long and very long",
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
Text(
' - ',
style: TextStyle(
fontSize: 10.0,
),
),
Flexible(
child: Text(
"Another quite long stuff, it's veeery long and by no means short",
style: TextStyle(
fontSize: 10.0,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
),
],
),
),
用Expanded
小部件包裝Text
小部件:
children: [
const Expanded(child:
Text(
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
textAlign: TextAlign.justify,
overflow: TextOverflow.ellipsis,
),
),
Text(
' - ',
style: TextStyle(
fontSize: 10.0,
),
),
const Expanded(child:
Text(
"yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
textAlign: TextAlign.justify,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 10.0,
),
),
),
],
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.