【发布时间】:2019-09-21 13:54:00
【问题描述】:
在我的应用程序中,我显示了几张卡片,每张卡片都包含标题、描述和一张图片。我正在从 json 响应中获取要显示的图像的名称,即图标字段。
我在 assets/name.png 中有我在 JSON 响应中得到的名称的图像。
我不知道如何获取图像,即如何通过该路径。
下面是我的代码的小sn-p。
createCard(BuildContext context, int count, var data) {
var colorFromJSON = data[count]['jsonString']['color'];
//here I am getting the name of the image from the icon field in the JSON Response
var iconName = data[count]['jsonString']['icon'];
var noHashColor = colorFromJSON.substring(1);
var colorHex = 0xFF000000 + int.parse(noHashColor, radix: 16);
if (data[count]['jsonString']['reportType'] == currentReportSummaryType) {
return Padding(
padding: EdgeInsets.all(10.0),
child: GestureDetector(
onTap: () {
setGenerateReportView(context, count, data);
},
child: Container(
//here I am adding
decoration: getCardDecoration(
"assets/dot_line_chart.png", new Color(colorHex)),
instead of hardcoding the image name as dot_line_chart.png, I
want it to be like contents of iconName field with png.
like "assets/iconName.png" how to do this
width: MediaQuery.of(context).size.width * 0.931,
height: MediaQuery
.of(context)
.size
.height * 0.16,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
【问题讨论】:
标签: flutter