flutter中的几种图片加载方式

博客介绍了Flutter中图片加载的相关内容,包括本地图片和网络图片的加载方式,网络图片可加载GIF,还有默认占位图、淡入效果等。同时提到了图片缓存,还列举了图片加载共同拥有的相关属性,如alignment、color等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

图片加载对应的有本地和网络之别,其中囊括了原生和插件,现在介绍点常用的:

  • 本地图片加载:new Image.asset("images/tupian.png")
    全路径填写,并在pubspec.yaml文件中注册

  • 网络图片加载:new Image.network( “https://cssccs”,fit: BoxFit.fill,width: 70,)
    可以加载GIF

  • 网络图片加载:FadeInImage.memoryNetwork有默认占位图和淡入效果
    https://pub.dartlang.org/packages/transparent_image


FadeInImage.memoryNetwork(
            image: 'https://xxx/lake.jpg',
            placeholder: kTransparentImage/* 透明图片 */,)
  • 网络图片加载:FadeInImage.assetNetwork 用本地图做占位图
FadeInImage.assetNetwork(
        image: 'https://xxx/lake.jpg',
        placeholder: 'images/birds.gif' /* 指定gif */,)),
    );
new CachedNetworkImage(
        fit: BoxFit.fill,
        width: 30,
        height:40,
        imageUrl:  avatar,
        placeholder: (context, url) => new ProgressView(),
        errorWidget: (context, url, error) => new Icon(Icons.error),
      );

共同拥有的相关部分属性;

  1. alignment → AlignmentGeometry
    How to align the image within its bounds

  2. centerSlice → Rect
    The center slice for a nine-patch image

  3. color → Color
    If non-null, this color is blended with each image pixel using colorBlendMode.

  4. colorBlendMode → BlendMode
    Used to combine(组合) color with this image

  5. excludeFromSemantics → bool
    Whether to exclude this image from semantics.

  6. filterQuality → FilterQuality
    Used to set the FilterQuality of the image

  7. fit → BoxFit
    How to inscribe the image into the space allocated during layout

  8. matchTextDirection → bool
    Whether to paint the image in the direction of the TextDirection.

  9. gaplessPlayback → bool
    Whether to continue showing the old image (true), or briefly show nothing (false), when the image provider changes

  10. image → ImageProvider
    The image to display.

  11. repeat → ImageRepeat
    . How to paint any portions(边缘) of the layout bounds not covered by the image.

  12. semanticLabel → String
    A Semantic description of the image.

  13. width、height → double

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值