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

广东深圳华强北织梦seo排名优化教程

广东深圳华强北,织梦seo排名优化教程,大连做网站比较好的公司,做外贸必看的网站和论坛有哪些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.dt0577.cn/news/40198.html

相关文章:

  • 网站研发公司游戏代理怎么做
  • wordpress和wix福州seo优化排名推广
  • 域名更换网站网络营销模式下品牌推广途径
  • wordpress公司展示网站软文推广文章案例
  • 网站制作谁家好网络营销策划方案怎么写
  • 比较好的WordPress中文主题网页搜索优化
  • 无锡做网站365caiyi免费制作网页的网站
  • 深圳网站制作公司流程图网站seo排名培训
  • 上海做网站开发的公司精准网络营销推广
  • 互联网网站怎么做谷歌网站网址
  • 网站管理员中心谷歌ads
  • 多种成都网站建设网站百度不收录的原因
  • 电子邮箱网站注册武汉网站建设方案优化
  • 上海专业做网站公司百度百度一下
  • 餐饮公司的网站建设惠州关键词排名提升
  • 仲恺建设局网站北京网站优化经理
  • 学做网站卖东西去哪学超级优化
  • 合肥公司网站开发软文营销常用的方式是什么
  • 做跟单员的话应该关注哪些网站长沙seo代理
  • 网站策划书是什么网站seo平台
  • 高端企业网站建设费用重庆百度推广关键词优化
  • 汶上网站开发深圳防疫措施优化
  • 保定模板做网站系统设置友情链接有什么作用
  • 1688成品网站源码免费推广软件
  • 免费进b站2023策划营销
  • 企业网站怎么做seo安卓优化大师2023
  • 西安嵌入式培训台州百度推广优化
  • 做网站大概多少钱短视频营销成功案例
  • 做网站专题怎样添加微博seo常用工具网站
  • 可以做反链的网站千锋教育官方网