我有一個水平 ListView,它位于列中,如果該串列溢位,我想在最后一個 Text 小部件上顯示省略號。我怎樣才能做到這一點?我在 Text 小部件上添加了 TextOverflow.ellipsis 但它仍然不起作用。所以我希望那個水平串列中的最后一項(在這種情況下是婦產科)在最后有 ... 。
class Card extends StatelessWidget {
@override
Widget build(BuildContext context) {
return FutureBuilder<DoctorData?>(
future: _bloc.getData(id: id, context: context),
builder: (context, snapshot) {
if (snapshot.hasData) {
final data = snapshot.data;
if (data != null) {
return GestureDetector(
onTap: () => (),
child: Container(
padding: const EdgeInsets.all(16),
child: Container(
padding: const EdgeInsets.all(8),
child: Row(
children: [
Image(data: data),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(data.name),
SizedBox(
height: 18,
child: ListView.separated(
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) => Text(
data.relations[index].code,
overflow: TextOverflow.ellipsis,
),
separatorBuilder: (_, __) => const Text(' · '),
itemCount: data.relations.length,
scrollDirection: Axis.horizontal,
),
),
],
),
),
const SizedBox(width: 8),
const ChevronRightIcon(),
],
),
),
),
);
}
}
return Container();
},
);
}
}
uj5u.com熱心網友回復:
如果你想使用省略號,它應該會溢位,但在 listView 中它只是擴展以占用空間,所以你可以將 subTitle 包裝在大小合適的框中。
SizedBox(
width: context.width * 0.9, // we are letting the text to take 90% of screen width
child: Text(
data.relations[index].code,
overflow: TextOverflow.ellipsis,
),
);
如果您有任何問題,請隨時在評論中留言,我會盡力解決這些問題。謝謝??
更新:
這是
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/508541.html