"FlutterError: Unable to load asset" while adding image from network
"FlutterError: Unable to load asset" while adding image from network
我试图将一些前导图像添加到某个流构建结构内的列表视图中。问题是无论我尝试什么,我总是得到同样的错误。我在 Whosebug 上做了一些研究,但我能找到的所有解决方案都是关于本地图像的,而不是来自互联网的图像。所以,我不知道如何将这些解决方案实施到我的项目中。
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" />
将资产图像更改为网络图像
backgroundImage: NetworkImage(
"https://www.kaspersky.com.tr/content/tr-tr/images/smb/icons/icon-ksos.png"),
),
我试图将一些前导图像添加到某个流构建结构内的列表视图中。问题是无论我尝试什么,我总是得到同样的错误。我在 Whosebug 上做了一些研究,但我能找到的所有解决方案都是关于本地图像的,而不是来自互联网的图像。所以,我不知道如何将这些解决方案实施到我的项目中。
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" />
将资产图像更改为网络图像
backgroundImage: NetworkImage(
"https://www.kaspersky.com.tr/content/tr-tr/images/smb/icons/icon-ksos.png"),
),