如何在Flutter中显示数组对象内的一些对象数据

huangapple go评论71阅读模式
英文:

How to display some object data inside array object Flutter

问题

I hope you have a great day, I'm still learning Flutter, and I have some difficulties displaying some data.

So I have this List data

listData = [{someData: Lorem #1, image: linkToSomeImage}]

and I need to display the image using Image.network(image).

But I don't know why. I tried listData[0].image or listData[0]["image"] to populate the variable, but it doesn't work, and I get all the red 如何在Flutter中显示数组对象内的一些对象数据

What is the correct way to do this?

英文:

i hope you have a great day, i'm still learn Flutter, and i have some difficulties to display some data

so i have this List data

listData = [{someData: Lorem #1, image: linkToSomeImage}]

and i need to display the image to Image.network(image),

but i don't know why, i tried listData[0].image or listData[0]["image"] to populate the variable but it can't works, and got all the red 如何在Flutter中显示数组对象内的一些对象数据

what is the correct way to do this?

答案1

得分: 1

数据将通过运算符[]key来访问,因为你有JSON(Map)列表。

listData[0]["image"]

使用方式如下:

Row(
  children: [
    for(int i=0; i< listData.length; i++)
      Image.network(listData[i]['image']),
  ]
)
英文:

As you have the list of json(Map), data will be accessed by operator [] with key

listData[0][&quot;image&quot;]

and usage will be

Row(
  children: [
    for(int i=0; i&lt; listData.length; i++)
      Image.network(listData[i][&#39;image`]),
  ]
)

huangapple
  • 本文由 发表于 2023年2月18日 12:55:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75491280.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定