[英]how to cache firebase images
import 'package:cloud_firestore/cloud_firestore.dart';
class PocketBooksModel {
String? docId;
String? title;
String? author;
String? image;
PocketBooksModel({this.docId, this.title, this.author, this.image});
PocketBooksModel.fromMap(DocumentSnapshot data) {
docId = data.id;
title = data["title"];
author = data["author"];
image = data["image"];
}
}
here is how the image is displayed in the ui code这是图像在 ui 代码中的显示方式
NetworkImage(PocketBooks['image']),
I have this class witch fetch data from firestore along with images in firebase storage.我有这个 class 女巫从 firestore 中获取数据以及 firebase 存储中的图像。 I want to cache the images after they load in the app.
我想在图像加载到应用程序后缓存它们。 How can i do that?
我怎样才能做到这一点?
You can use the cached.network_image package which you can get from pub.dev您可以使用从 pub.dev 获得的 cached.network_image package
Once you imported the package on you widget you can use a widget like this to cache the image在您的小部件上导入 package 后,您可以使用这样的小部件来缓存图像
CachedNetworkImage(
imageUrl: imageUrl ,
imageBuilder: (context, imageProvider) =>
CircleAvatar(backgroundImage: imageProvider),
placeholder: (context, url) => const Center(
child:
CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(
primary,
),
),
),
errorWidget: (context, url, error) {
return const Center(
child: Icon(Icons.error, color: Colors.red),
);
},
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.