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

营销网站开发找哪家天津市网站建设+网页制作

营销网站开发找哪家,天津市网站建设+网页制作,折叠网站开发工程师,wordpress修改网址导航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/693399/

相关文章:

  • 广州沙河一起做网站wordpress 开发实例
  • 中国小康建设网 官方网站哪个app推广佣金高
  • 重庆网站备案系统中国新设计师联盟
  • 商丘旅游网站的建设网站推广工作
  • 温州网站定制公司哪家好好大夫在线免费咨询
  • 投注类网站怎么做自动软件做后期哪个网站素材好
  • 自己电脑做电影网站做网站的表情包
  • 长安网站建设软件开发thinkphp 微网站开发
  • 铜官山区建设局网站成都创软科技的口碑
  • 有没有免费网站制作电脑做网站电脑编程
  • 桂林网站推广网站建设提案怎么写
  • 什么网站下载素材做图的自己做网站怎么跳过备案
  • 中国网站用Cn域名金融投资理财网站建设
  • 河南建筑公司实力排名网络规划与优化技术学什么
  • 深圳网站建设服务公内蒙古网站建设熊掌号
  • 公司部门网站设计模板熊掌号如何做网站
  • 学校加强网站建设gps建站步骤视频
  • 网站跳出率 报告网站建设满意度调查问卷
  • 旺苍网站建设jsp网站开发难点
  • wordpress教程下载网站主题怎么样给一些小网站做链接
  • 专门做音箱的网站公司网站备案需要多久
  • 炫酷的网站开发深圳app定制开发报价单
  • 高端手机网站 制作公司上海有名的科技公司
  • 高级网站建设有没有类似一起做网店的网站
  • 网站平台搭建和维护需要什么wordpress培训班
  • 河南网站建设首选公司苏州做网站优化的
  • 学做凉菜冷菜的网站wordpress获取用户名
  • 网站建设与管理学习收获开发者选项怎么设置最流畅
  • 如何查看网站外链招聘网站怎么做吸引人
  • 城市建设厅官方网站怎样自己制作手机app软件