gpt4 book ai didi

flutter - Flutter-如何对齐文本和图像小部件?

转载 作者:行者123 更新时间:2023-12-03 04:26:18 24 4
gpt4 key购买 nike

我有一个Card,其中包含多个Text和一个Image。现在,图像位于顶部中心位置,我需要将其与卡内的右侧对齐。

我需要所有文本在卡的左侧,图像在右侧。

因此,基本上所有Text应该在左侧,而Image应该在右侧。

这是我现在实现的卡

enter image description here

这是我已经实现的代码

  Widget _buildItemsForListView(BuildContext context, int index) {
return Card(
child: Column(
children: <Widget>[
Image.asset(Constants.FOOD_PLACEHOLDER_IMAGE_ASSET_URL, height: 50,width: 100),
Text("Spinach soup",
style: TextStyle(color: Colors.deepPurple, fontSize: 16),
textAlign: TextAlign.left,),
Text("SAR",
style: TextStyle(color: Colors.black, fontSize: 14),
textAlign: TextAlign.left),
Text("26",
style: TextStyle(color: Colors.black, fontSize: 14),
textAlign: TextAlign.left,),
Text(
"Fresh spinach, mushrooms, and hard-boiled egg served with warm bacon vinaigrette",
style: TextStyle(color: Colors.black, fontSize: 14),
textAlign: TextAlign.left,),
Text("15.4" + " Calories",
style: TextStyle(color: Colors.black, fontSize: 14),
textAlign: TextAlign.left,)
],
),
);
}

如何实现呢?

任何的意见都将会有帮助。

最佳答案

Card(
child: Row(
children: <Widget>[
Expanded(
flex: 5,
child: Column(
mainAxisSize:MainAxisSize.min,
crossAxisAlignment:CrossAxisAlignment.start,
children: <Widget>[
Text(
"Spinach soup",
style: TextStyle(color: Colors.deepPurple, fontSize: 16),
textAlign: TextAlign.left,
),
Text("SAR",
style: TextStyle(color: Colors.black, fontSize: 14),
textAlign: TextAlign.left),
Text(
"26",
style: TextStyle(color: Colors.black, fontSize: 14),
textAlign: TextAlign.left,
),
Text(
"Fresh spinach, mushrooms, and hard-boiled egg served with warm bacon vinaigrette",
style: TextStyle(color: Colors.black, fontSize: 14),
textAlign: TextAlign.left,
),
Text(
"15.4" + " Calories",
style: TextStyle(color: Colors.black, fontSize: 14),
textAlign: TextAlign.left,
)
],
),
),
Expanded(
flex: 1,
child: Image.network(
'https://3.img-dpreview.com/files/p/TS1200x900~sample_galleries/1330372094/1693761761.jpg',
height: 50,
width: 100),
)
],
),
)

Screenshot

关于flutter - Flutter-如何对齐文本和图像小部件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59552094/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com