【问题标题】:how to pass the value to a file path in dart/Flutter如何将值传递给 dart/Flutter 中的文件路径
【发布时间】: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


    【解决方案1】:

    这可能会有所帮助

    decoration: new BoxDecoration(
          image: new DecorationImage(image: new NetworkImage(data[count]['imageName']['reportType']),
          fit: BoxFit.cover)
        ),
    

    https://stackoverflow.com/a/50714191/6450434

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-11
      • 1970-01-01
      • 1970-01-01
      • 2021-11-16
      • 1970-01-01
      • 2020-10-17
      • 2018-01-22
      相关资源
      最近更新 更多