【发布时间】:2021-02-20 09:16:24
【问题描述】:
Column(
children: [
Padding(
padding: const EdgeInsets.only(
left: 15, bottom: 8, top: 1),
child: Row(
//crossAxisAlignment: CrossAxisAlignment.start,
//mainAxisAlignment: MainAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// ITEM NAME
Padding(
padding: const EdgeInsets.only(
left: 10, top: 10),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
'${restaurantItems[i].name}',
style: TextStyle(
fontSize: 17,
color: kTextColor,
fontWeight: FontWeight.w700),
),
SizedBox(
width: width / 2,
),
// 'ADD' BUTTON CONTAINER
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(8),
color: Colors.black87,
),
child: Padding(
padding: const EdgeInsets.only(
left: 9,
top: 3,
right: 5,
bottom: 3),
child: InkWell(
splashColor: Colors.white,
onTap: () {
// print(restaurantItems[i].name);
cart.addItem(
restaurantItems[i].id,
restaurantItems[i].name,
restaurantItems[i].price,
restaurant,
);
},
child: Row(
children: [
Text(
'ADD',
style: TextStyle(
color: Colors.white,
),
),
Icon(
Icons.add,
color: Colors.white,
size: 17,
),
],
),
),
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(
left: 10, top: 10, bottom: 11),
child: Text(
'₹${restaurantItems[i].price}',
style: TextStyle(
fontSize: 15,
color: kTextColor,
fontWeight: FontWeight.w500),
),
),
// Padding(
// padding: const EdgeInsets.only(
// left: 17, top: 17),
// child: InkWell(
// onTap: () {
// // Add to Cart
// },
// child: Row(
// children: [
// Padding(
// padding:
// const EdgeInsets.only(left: 15),
// child: Text(
// '${restaurantItems[i].quantity} Left',
// style: TextStyle(
// color: kTextLightColor,
// fontSize: 13,
// fontWeight: FontWeight.w700),
// ),
// )
// ],
// ),
// ),
// )
],
),
],
),
),
],
),
如何填充“ITEM NAME”和“ADD CONTAINER”之间的空格?我已经尝试过 spacer(),但它不起作用。另外,我见过 Expanded() 小部件,但由于我是新来的,我似乎无法掌握它。我还添加了 Column 小部件,因此我猜 Spacer() 小部件无法正常工作。 任何帮助将不胜感激,谢谢。
【问题讨论】:
-
这个小部件是否在
Column中?你能提供整个小部件树吗?你的代码看起来不错。我猜有些parent widget正在限制您的项目小部件的width。 -
只需将
Row的mainAxisSize设置为MainAxisSize.Max即可。 -
是的,它在@YoBo 列中
-
我认为,
Spacer应该可以工作。您能否分享一张使用 Spacer 的屏幕截图以及您希望它看起来是什么样子的屏幕截图? -
@PreetShah 他不需要带有 mainAxisAlignment 的 Spacer:MainAxisAlignment.spaceBetween。它基本上会在项目之间为您添加它。我在一个测试应用程序中尝试了他的示例并且它有效。他的问题很可能来自父部件树,但由于我们看不到全貌,我们无法帮助他。
标签: flutter dart flutter-layout