我是新手,会尝试将一些自定义图像加载到我的项目中并将其转换为图标。图像存储在Firebase存储中,但是我在数据库中包含了每个图像的url。当我尝试加载每个图像并将其转换为图标时,它们变为灰色。这是代码...
class BodyOne extends StatefulWidget {
@override
_BodyOneState createState() => _BodyOneState();
}
class _BodyOneState extends State<BodyOne> {
Future getEvents() async {
var firestore = Firestore.instance;
QuerySnapshot qn = await firestore.collection('events').getDocuments();
return qn.documents;
}
@override
Widget build(BuildContext context) {
return Container(
child: FutureBuilder(
future: getEvents(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: Text('Loading...'),
);
} else {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (_, index) {
return ListTile(
leading: ImageIcon(
NetworkImage(snapshot.data[index].data['img_url']),
),
title: Align(
child: TitleText(
title: snapshot.data[index].data['eventName']),
alignment: Alignment(-1.2, 0),
),
);
},
);
}
},
),
);
}
}
这是它返回的内容:任何帮助将不胜感激。
最佳答案
不要这样做,只需要使用Image class并将height
和width
赋予数据即可。
leading: Image(
image: NetworkImage(snapshot.data[index].data['img_url']),
width: your_width,
height: your_height,
fit: BoxFit.cover,
color: null // this is the work around
)