【发布时间】:2023-02-24 02:48:49
【问题描述】:
我正在使用 Listview.builder 来展示产品。 我使用 mediaquery 检查屏幕宽度是否足够大,然后它会使用 Grideview,如下图所示,但只有 Grideview 有问题,这超出了 Stack Height 我用 flutter devTools 检查并发现堆栈中的列正在占用它是最小尺寸那么是什么导致堆栈这么大?
child: Stack(
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: [
// Work Image
AspectRatio(
aspectRatio: 16.0 / 9.0,
child: Image.asset(
Constants.appLogo,
fit: BoxFit.cover,
),
),
Padding(
padding: const EdgeInsets.only(
left: Sizes.PADDING_18,
bottom: Sizes.PADDING_8,
right: Sizes.PADDING_8,
),
// Work Title, Adress
child: Row(
children: [
Flexible(
child: Text(
testAdress.length > 25
? '${testAdress.substring(0, 25)}...'
: testAdress,
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: const TextStyle(
fontWeight: FontWeight.w600,
fontSize: Sizes.TEXT_SIZE_22,
),
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(
left: Sizes.PADDING_18,
bottom: Sizes.PADDING_8,
right: Sizes.PADDING_8,
),
//SubTitle
child: Row(
children: [
Flexible(
child: FittedBox(
fit: BoxFit.scaleDown,
alignment: Alignment.bottomLeft,
child: Text(
testAdress.length > 34
? '${testAdress.substring(0, 34)}...'
: testAdress,
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: TextStyle(
fontSize: Sizes.TEXT_SIZE_14,
color: Colors.grey.withOpacity(0.8),
),
),
),
),
],
),
),
],
),
],
),
),
],
),
【问题讨论】:
-
你可以用 `aspectRatio: 16.0 / 9.0,` 包装堆栈