如何通过CircleAvatar从数据库显示图像

时间:2020-08-07 03:21:10

标签: flutter dart

我正在尝试通过CircleAvatar显示来自数据库的图像数据,但是在此过程中出现了一些错误,我们将不胜感激任何建议,并且此错误也'不能将参数类型'Iterable'分配给该参数类型“ ImageProvider”。

leading: CircleAvatar(
   backgroundColor: Colors.blueAccent,
   backgroundImage: images.map((photo){
       return Utility.imageFromBase64String(snapshot.data[index].profilepicture);
   }),
),

1 个答案:

答案 0 :(得分:1)

这是因为从返回数据中获得了Iterable类型,而不是ImageProvider类型。如果您的snapshot.data[index].profilepicture是URL字符串。

您只能在下面使用代码。

CircleAvatar(
  backgroundImage: NetworkImage(
     snapshot.data[index].profilepicture,
    ),
),