【发布时间】:2022-01-14 01:44:20
【问题描述】:
我正在尝试在我的小部件中创建一个框,该框将根据其中发布的内容动态调整大小,但它似乎在遇到溢出时被截断。
Padding _buildReviewsSnapshot(Tasker user) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 5.0),
child: Row(
children: [
Expanded(
// flex: 3,
child: GridView.count(
crossAxisCount: 2,
shrinkWrap: true,
children: List.generate(6, (index) {
return Container(
decoration: BoxDecoration(
border: Border.all(
color: const Color.fromRGBO(212, 221, 230, 1)),
borderRadius:
const BorderRadius.all(Radius.circular(20))),
margin: const EdgeInsets.all(6),
clipBehavior: Clip.antiAlias,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(children: [
Row(children: const [
Icon(
Icons.star_rate,
size: 16,
color: Colors.amber,
),
Icon(
Icons.star_rate,
size: 16,
color: Colors.amber,
),
Icon(
Icons.star_rate,
size: 16,
color: Colors.amber,
),
Icon(
Icons.star_rate,
size: 16,
color: Colors.amber,
),
Icon(
Icons.star_border,
size: 16,
color: Colors.grey,
),
]),
const SizedBox(height: 10),
Text(
"Charlee wasn’t present at the job but we had extremely clear instructions on what to do and how to do it. Would highly recommend as the attention to detail was spot on",
style: Theme.of(context).textTheme.bodyText1),
Text("- Charlee R",
style: Theme.of(context).textTheme.bodyText2),
]),
));
}),
)),
],
));
}
【问题讨论】:
-
尝试用
Flexible包裹Text -
这会导致溢出,我所追求的是让带有边框的容器扩大或缩小到内容的大小
-
您能否添加屏幕截图,说明哪种类型的错误或您的实际结果?
-
@BossNass 你可以使用 IntrinsicHeight,请参考这个,api.flutter.dev/flutter/widgets/IntrinsicHeight-class.html
-
所有容器的大小或动态是否相同?
标签: flutter flutter-layout containers expand