当前位置: 首页 > news >正文

常州溧阳网站建设培训课程网站

常州溧阳网站建设,培训课程网站,哪些网站是响应式,3建网站flutter开发实战-显示本地图片网络图片及缓存目录图片 在最近开发中碰到了需要显示缓存目录图片,这里顺便整理一下,显示本地图片、网络图片、缓存目录图片的方法。 一、工程本地图片显示 1 在项目根目录下创建名为 images文件夹,也可以将i…

flutter开发实战-显示本地图片网络图片及缓存目录图片

在最近开发中碰到了需要显示缓存目录图片,这里顺便整理一下,显示本地图片、网络图片、缓存目录图片的方法。

一、工程本地图片显示

  • 1 在项目根目录下创建名为 images文件夹,也可以将images放在asserts文件夹下
  • 2.在pubspec.yaml中配置images相关的路径,并执行pub get 使配置的文件生效

在pubspec.yaml文件中

# The following section is specific to Flutter.
flutter:# The following line ensures that the Material Icons font is# included with your application, so that you can use the icons in# the material Icons class.uses-material-design: trueassets:- assets/images/- assets/images/common/- assets/images/icons/

调用本地图片显示代码


Widget _buildLoadingWidget(BuildContext context) {return ImageHelper.wrapAssetAtImages("icons/ic_toast_loading.png",width: 50.0,height: 50.0,);}// ImageHelper.wrapAssetAtImages
static Image wrapAssetAtImages(String name,{double? width, double? height, BoxFit? fit}) {return Image.asset("assets/images/" + name,width: width,height: height,fit: fit,errorBuilder: (context, url, error) =>imageErrorHolder(width: width, height: height),);}

还可以使用AssetImage及Image.asset


Image(image: AssetImage("assets/images/icons/ic_toast_loading.png"),width: 100.0
);Image.asset("assets/images/icons/ic_toast_loading.png",width: 100.0
);

二、显示网络图片

网络图片显示,使用NetworkImage 可以加载网络图片


Image(image: NetworkImage("imageUrl"),width: 100.0,
)

使用Image.network

Image.network("https://avatars2.githubusercontent.com/u/20411648?s=460&v=4",width: 100.0,
)

使用cached_network_image插件实现加载图片

// 处理网络图片的urlstatic Widget imageNetwork({required String imageUrl,double? width,double? height,BoxFit? fit,Widget? placeholder,Widget? errorHolder}) {double? cacheWidth;if (width != null) {cacheWidth = width * 2.0;}double? cacheHeight;if (height != null) {cacheHeight = height * 2.0;}if (!(imageUrl.isNotEmpty && imageUrl.startsWith("http"))) {return Container();}String aCropImageUrl = ImageHelper.formatImageUrl(imageUrl: imageUrl, width: cacheWidth, height: cacheHeight);return CachedNetworkImage(maxWidthDiskCache: cacheWidth?.round(),maxHeightDiskCache: cacheHeight?.round(),imageUrl: aCropImageUrl,fit: fit,width: width,height: height,placeholder: (context, url) => (placeholder ?? Container()),errorWidget: (context, url, error) =>(errorHolder ?? imageErrorHolder(width: width, height: height)),);}static Widget imageErrorHolder({double? width, double? height}) {return Container(width: width,height: height,);}static Widget placeHolder({double? width, double? height}) {return SizedBox(width: width,height: height,child: CupertinoActivityIndicator(radius: min(10.0, width! / 3)));}

三、加载缓存目录图片

当我们将图片保存到Document、Cache目录下,需要将其显示出来,知道的ImagePath,可以使用File(ImagePath)将图片显示出来。

String? imagePath = picArg!['imagePath'];if (imagePath != null) {return Image.file(File(imagePath!),width: widget.width,height: widget.height,fit: BoxFit.cover,);}

当然也可以实现ImageProvider来处理显示图片问题

四、小结

flutter开发实战-显示本地图片网络图片及缓存目录图片。显示本地图片、网络图片、缓存目录图片的几种方法

学习记录,每天不停进步。

http://www.hrbkazy.com/news/10844.html

相关文章:

  • 网站开发 流程图成都百度推广联系方式
  • 网站建设案例ppt阿里网站seo
  • 云服务器可以做多个网站百度招聘官网
  • 房产网站怎么推广seo运营人士揭秘
  • 网站运营目的百度自助建站官网
  • 网站设计教程网络营销策划ppt
  • 健身器材网站源码网站制作流程和方法
  • 广州安全教育平台初始密码东莞seo网站优化排名
  • 南阳哪里做网站比较好搜索百度app下载
  • 做网站公司的未来seo关键字优化软件
  • 无锡本地模板网站建设产品女排联赛最新排行榜
  • 公司网站设计与制深圳龙华区大浪社区
  • 有没有什么网站免费做名片友情链接交换平台免费
  • 衡阳百度网站建设seo岗位职责
  • 素材网站源码百度做免费推广的步骤
  • 网站建设简介百度导航最新版本
  • 西宁网站建设平台公司百度一下你就知道官网网页
  • 阜阳做网站哪家好北京seo收费
  • 音乐介绍网站怎么做怎样做网站推广啊
  • 英文都不懂 学网站建设维护难吗怎么做网络营销推广啊
  • 服务佳的小企业网站建设百度搜索引擎盘搜搜
  • php网站开发优化seo优化一般多少钱
  • 山东建设执业资格注册中心网站网络营销推广专员
  • 网站正在建设中html电子商务是干什么的
  • 做城市分类信息网站好做吗站长推荐黄色
  • 公司给别人做的网站违法吗深圳seo优化服务
  • 购物类网站如何对seo进行优化
  • ml免费域名注册南京百度seo排名优化
  • 企业网站管理系统湖南岚鸿网络公关
  • 教育主管部门建设的专题资源网站搜索引擎优化策略不包括