【发布时间】:2020-11-17 03:57:56
【问题描述】:
我正在尝试在 Flutter 中做这样的事情:
但我需要使产品名称、价格和最后的信息相互对齐。
图像将始终具有相同的高度和宽度,但名称可以具有任意长度。
我现在的代码(obs:我对颤振没有太多经验):
final columnCount = 2;
final width = MediaQuery.of(context).size.width / columnCount;
const height = 400;
GridView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
padding: EdgeInsets.all(10.0),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
childAspectRatio: width / height,
crossAxisCount: columnCount,
mainAxisSpacing: 10.0,
crossAxisSpacing: 10.0,
),
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
if (index < snapshot.data.length) {
return InkWell(
onTap: null,
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 16),
),
Container(
child: AspectRatio(
aspectRatio: 1,
child: Image.network(snapshot.data[index].image,fit: BoxFit.cover,),
),
// height: 250,
),
Padding(
padding: EdgeInsets.only(top: 16),
),
Text(snapshot.data[index].title,
textAlign: TextAlign.center),
Padding(
padding: EdgeInsets.only(top: 16),
),
Text(
'${helpers.formatMoney(snapshot.data[index].lowPrice)}' +
'-' +
'${helpers.formatMoney(snapshot.data[index].highPrice)}',
textAlign: TextAlign.center),
Padding(
padding: EdgeInsets.only(top: 16),
),
RaisedButton(
onPressed: () async {
cart = await addCart(widget.segment.slug,
snapshot.data[index].token, 1);
setState(() {});
},
child: Icon(Icons.add_shopping_cart),
),
],
)));
})
【问题讨论】: