我试图将一些前导影像添加到某些 Stream Build 结构内的串列视图中。问题是无论我尝试过什么,我总是遇到同样的错误。我在 Stackoverflow 中做了一些研究,但我能找到的所有解决方案都是关于本地影像,而不是来自互联网的影像。所以,我不知道如何将这些解决方案实施到我的项目中。
Widget build(BuildContext context) {
final Stream<QuerySnapshot> _stuffStream = FirebaseFirestore.instance
.collection('Stuffs')
.orderBy('dateTime',
descending: true)
.snapshots();
return StreamBuilder<QuerySnapshot>(
stream: _stuffStream,
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) {
return Text('Please try again');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Text("Please wait");
}
return ListView(
children: snapshot.data!.docs.map((DocumentSnapshot document) {
Map<String, dynamic> data =
document.data()! as Map<String, dynamic>;
return ListTile(
leading: CircleAvatar(
backgroundImage: AssetImage(
"https://www.kaspersky.com.tr/content/tr-tr/images/smb/icons/icon-ksos.png"),
),
title: Text(data['title']),
subtitle: Column(
children: <Widget>[
Text(data['details']),
TextButton(
child: const Text('Send message'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChatPage(docs: data)));
}),
TextButton.icon(
icon: Icon(Icons.favorite),
label: Text('Favorite'),
onPressed: () async {
favorite(data['stuffID']);
}),
],
),
);
}).toList(),
);
});
}
}
我也尝试使用它,但我遇到了同样的错误:
leading: SizedBox(
height: 100.0,
width: 100.0, // fixed width and height
child: Image.asset(data['stuffImage']))
我还将此权限添加到 AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
uj5u.com热心网友回复:
将资产影像更改为网络影像
backgroundImage: NetworkImage(
"https://www.kaspersky.com.tr/content/tr-tr/images/smb/icons/icon-ksos.png"),
),
0 评论