flutter中的几种图片加载方式

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

  • 本地图片加载: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 */,)),
    );
  • 图片缓存:cached_network_image
    https://pub.dartlang.org/packages/cached_network_image
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

你可能感兴趣的:(flutter)