赞
踩
加载网络图片时,有时候因为一些原因导致加载缓慢。所以可以选择如下方式添加占位图。
FadeInImage(
width: 100,
fit: BoxFit.cover,
placeholder: NetworkImage("占位图网址"),
image: NetworkImage("实际渲染图片网址")
)
ClipRRect(
borderRadius: BorderRadius.circular(200.dp),
child: FadeInImage(
placeholder: NetworkImage("占位图网址"),
image: NetworkImage("实际渲染图片网址")
)
四个参数如下:
Image.network( "实际渲染图片网址", errorBuilder: (context, error, stackTrace) { return CircularProgressIndicator(); }, frameBuilder: (context, child, frame, wasSynchronousLoaded){ if(wasSynchronousLoaded){ return child; } return AnimatedOpacity( /// 淡出效果 child: child, opacity: frame == null ? 0 : 1, duration: const Duration(seconds: 2), curve: Curves.easeOut, ); } )
四个参数如下:
Image.network( "实际渲染图片网址", errorBuilder: (context, error, stackTrace) { return CircularProgressIndicator(); }, loadingBuilder: (context, child, loadingProgress){ if(loadingProgress == null){ return child; } return Container( alignment: Alignment.center, child: CircularProgressIndicator( value: loadingProgress.expectedTotalBytes != null ? loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes! : null, ), ); } )
进度条
CircularProgressIndicator如下参数:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。