【发布时间】:2021-10-13 05:20:57
【问题描述】:
我有一个Container,也有一个Text 作为child。问题是我的text 在右侧溢出。但实际上我希望它打破并且父容器应该展开。
这就是现在的样子:
还有我的代码:
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: Padding(
padding: EdgeInsets.only(
bottom: 14.scaled,
),
child: Container(
// height: 70.scaled,
decoration: BoxDecoration(
boxShadow: [verySoftDarkShadow],
color: white,
borderRadius: BorderRadius.circular(10.scaled),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: 20.scaled,
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
shortArticle.label!,
style: alternativeText,
),
Text(
shortArticle.manufacturerLabel ?? '',
style: alternativeText.copyWith(color: darkGray),
),
],
),
Spacer(),
SvgIconButton(
onTap: () {
print('tapped');
},
svgPath: 'images/vertical_menue_dots.svg',
width: touchTargetSizeForIconButton,
height: touchTargetSizeForIconButton,
svgSize: 16.scaled,
),
],
),
),
),
);
}
}
我尝试将text-widget 包装在Expanded 中,但这只会使其溢出并且不显示任何内容。我在这里想念什么?我该如何解决这个问题?
如果您需要更多信息,请告诉我!
【问题讨论】:
-
在 Expanded 或 Flex Widget 中添加您的 Widget 参考我的回答 here
-
@RavindraS.Patil 我尝试将文本包装在 Expanded 中,但这并没有解决问题:(
-
尝试添加 SizedBox() 而不是 Spacer()
-
@RavindraS.Patil 结合 Kuku 的解决方案为我修复了它:) 你能解释一下为什么 SizedBox 可以工作,但 Spacer() 会引发一些奇怪的行为吗?
-
Spacer 占用任何可用空间,而 SizedBox 具有特定的宽度和高度
标签: flutter dart text widget constraints