gpt4 book ai didi

flutter - 无法将 NetworkImage 分配给类型 Widget

转载 作者:IT王子 更新时间:2023-10-29 06:36:17 25 4
gpt4 key购买 nike

我尝试通过执行以下操作将图像添加到我的 ListView

new ListView(
children: <Widget>[
new NetworkImage('my_image_url')
]
)

出现以下错误:

The element type 'NetworkImage' can't be assigned to the list type 'Widget'.

最佳答案

NetworkImage不是小部件,而是:

Fetches the given URL from the network, associating it with the given scale.

因此,它被用在像 CircleAvatar 这样的 Widget 中,以提供其图像的来源。

通过 url 添加图像的正确方法是使用 Image.network('url'):

new ListView(
children: <Widget>[
new Image.network('my_image_url')
]
)

关于flutter - 无法将 NetworkImage 分配给类型 Widget,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47147973/

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