图片网络请求
Image.network(
FirebaseStorage.instance
.ref()
.child(blog.data["picture1"])
.getDownloadURL()
.toString(),
),
picture1是格式为“ blogPic / $ {email} / $ {number} _a”的字符串。 该字符串指向消防位置。
错误
The following assertion was thrown resolving an image codec:
Unable to load asset: Image(image: NetworkImage("Instance of 'Future<dynamic>'", scale: 1.0), frameBuilder: null, loadingBuilder: null, alignment: center, this.excludeFromSemantics: false, filterQuality: low)
When the exception was thrown, this was the stack:
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:664:31)
#2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:648:14)
#3 ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:501:13)
...
Image provider: AssetImage(bundle: null, name: "Image(image: NetworkImage("Instance of 'Future<dynamic>'", scale: 1.0), frameBuilder: null, loadingBuilder: null, alignment: center, this.excludeFromSemantics: false, filterQuality: low)")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#33ea4(), name: "Image(image: NetworkImage("Instance of 'Future<dynamic>'", scale: 1.0), frameBuilder: null, loadingBuilder: null, alignment: center, this.excludeFromSemantics: false, filterQuality: low)", scale: 1.0)
答案 0 :(得分:0)
使用FutureBuilder小部件
FutureBuilder(builder: (context , snapshot){
switch(snapshot.connectionState){
case ConnectionState.none:
return Text('No Data');
break;
case ConnectionState.waiting:
return Container(
width: 200,
height: 200,
child: CircularProgressIndicator(),
);
break;
case ConnectionState.active:
return Container(
width: 200,
height: 200,
child: CircularProgressIndicator(),
);
break;
case ConnectionState.done:
return Container(
width: 200,
height: 200,
child: Image.network(snapshot.data.toString() , fit: BoxFit.contain,),
);
break;
}
return Container(
width: 200,
height: 200,
child: CircularProgressIndicator(),
);
}, future: _getImage(document['filePath']),)
Future<String> _getImage(filePath) async{
String url = await storage.ref().child('launch').child('$filePath.jpg').getDownloadURL().whenComplete((){
}).catchError((error){
return null;
});
return url;
}