我使用类获取图像
class ImageLoader extends StatefulWidget{
final String imageBytes;
final Brand brand;
const ImageLoader({Key key, this.imageBytes, this.brand}) : super(key: key);
@override
Widget build(BuildContext context, index){
_ImageLoaderState();
}
@override
_ImageLoaderState createState() => _ImageLoaderState();
}
class _ImageLoaderState extends State<ImageLoader> {
final FirebaseStorage storage = FirebaseStorage(
storageBucket: 'gs://any.appspot.com');
String errorMsg;
String imageBytes;
_ImageLoaderState() {
storage.ref().child('images/image.jpeg').getDownloadURL().then((url) =>
setState(() {
imageBytes = url;
})
).catchError((e) =>
setState(() {
errorMsg = e.error;
})
);
}
@override
void initState() {
super.initState();
imageBytes = widget.imageBytes;
}
@override
Widget build(BuildContext context) {
return Container(child: Image.network(imageBytes, fit: BoxFit.fill,));
}
}
如何使用数据文件调用图像?
调用图像路径对我来说看起来像这样'${brand.model[0].model_image.image}'
以images/folder/image.jpeg格式返回图像的路径
当我尝试添加${brand.model[0].model_image.image}到孩子时,我storage.ref().child('images/image.jpeg').getDownloadURL().then((url)得到错误品牌未初始化但是当我尝试初始化品牌时,我得到(url = null)
一般来说,我正在尝试获取'gs://any.appspot.com' + '${brand.model[0].model_image.image}'特定图像的链接,以便我的 ListView.builder 将显示给定索引的图像
谢谢你的帮助
理论上应该是这样的: