我正在使用一行,在其中,每個文本都是一列,我希望每當我的文本溢位時,它應該自動轉到下一行,我嘗試了所有方法,但它不起作用。當我嘗試使用擴展或靈活時,它出錯了。我嘗試制作 maxlines 2,然后使用擴展/靈活,我還給了它一個容器作為父小部件,并使其高度足夠大,但仍然錯誤。
這是代碼片段-
class RouteItems extends StatelessWidget {
final int index;
final NodeElement data;
RouteItems({required this.index, required this.data});
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Column(
children: [
SvgPicture.asset(
'assets/icons/road-straight-line-top-view.svg',
height: 15,
width: 80,
),
SvgPicture.asset(
filterRoutesIcon("${data.node?.type}"),
height: 30,
width: 30,
),
SvgPicture.asset(
'assets/icons/road-straight-line-top-view.svg',
height: 15,
width: 80,
),
],
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Container(
//height: 60,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
'${data.node?.name}',
style: TextStyle(fontSize: 12.0),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
Text(
data.eta!.getFormattedDate('hh:mm a, d MMM'),
style: TextStyle(fontSize: 10.0, color: colorDarkGrey),
)
],
),
),
),
],
),
Align(
alignment: Alignment.centerRight,
child: Icon(
Icons.timer,
),
),
],
);
}
}

uj5u.com熱心網友回復:
嘗試將您不想溢位的文本包裝在 Flexible() 小部件中。這將確保它不會在行中占用比可用空間更多的空間。
uj5u.com熱心網友回復:
這個Row可以去掉,它的目的是什么?
Row(
children: [
Text(
'${data.node?.name}',
style: TextStyle(fontSize: 12.0),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
)
您可以嘗試洗掉maxLines: 1, 并添加寬度約束到您的Texteg 用 a 包裹它SizedBox,這樣文本將換行到下一行:
SizedBox(
width: 200,
child: Text(
'${data.node?.name}',
style: TextStyle(fontSize: 12.0),
),
)
uj5u.com熱心網友回復:
您還可以添加或替換 SizedBox 小部件的寬度引數
width: MediaQuery.of(context).size.width,
將 Text 子項限制為設備螢屏寬度。
uj5u.com熱心網友回復:
你可以試試這個方法
Expanded(
Row(
children: [
Card(
child: Text(" My awseome no overflow text"),),
..Other Widgets
]
),
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/390195.html
上一篇:C語言在STM32中的記憶體分配
