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

东莞大岭山做网站公司微信公众号 wordpress

东莞大岭山做网站公司,微信公众号 wordpress,wordpress options framework,软件开发培训学校排名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.yayakq.cn/news/648647/

相关文章:

  • 沈阳 网站建设建站行业成为买方市场
  • 网站建设维护一年费用有什么网站是可以做动态图的
  • 学院网站建设作用如何制作图片配文字
  • 中企动力网站模板wordpress设置字体
  • 商业网站开发选题的目的红色企业网站
  • 上海做网站设计的公司给网站做cdn
  • 如何做好电商网站asp.net 网站管理系统
  • 东莞网站建设php方案如何把php做的网站做成app
  • 程序员网上接单seo优化代理
  • 网站建设内部因素做网站费用列入什么科目
  • 网站开发最新效果营销系统
  • 遵义住房和城乡建设局官方网站北大荒建设集团有限公司网站
  • 建筑工程网站建设方案vs网站开发 怎么运行
  • 国外建站程序开发公司网站公司
  • 免费开源的企业建站系统室内设计手绘图
  • 一个人可以做网站吗网站后台管理密码忘记
  • 怎样向顾客电销网站建设wordpress百度自动推送
  • 企业网站营销网站河北网站优化
  • qq浏览器网页版进入公司网站中新闻中心怎样做优化
  • 陕西做网站公司有哪些满城区建设局网站
  • 怎样找公司做单的网站深圳2024新冠最新情况
  • 遵义高端网站建设哪个网站教做公众号
  • 西宁网站建设磁力狗最佳搜索引擎
  • 广东平台网站建设平台wordpress标题前缀
  • 自学移动端网站开发网页设计与制作自学
  • 金湖网站设计在百度云上做网站
  • 网站 集约化平台建设方案的通知莱芜网站设计公司
  • 北京外包推广百度推广怎么做网站的优化
  • 做自己的网站需要多少钱珠海市做网站
  • 编写网站代码一流的成都 网站建设