Flutter 什么功能都有的Image

Pub上面关于Image的插件挺多的,但是为啥我还是想要做一个呢,主要是pub上面感觉不够自定义化。

extended_image跟官方的用法一模一样,但是增加了许多实用的功能。

缓存网络图片

ExtendedNetworkImageProvider除了缓存的功能还提供了重试,超时等功能

 ExtendedNetworkImageProvider(this.url,
      {this.scale = 1.0,
      this.headers,
      this.cache: false,
      this.retries = 3,
      this.timeLimit,
      this.timeRetry = const Duration(milliseconds: 100)})
      : assert(url != null),
        assert(scale != null);

  ///time Limit to request image
  final Duration timeLimit;

  ///the time to retry to request
  final int retries;

  ///the time duration to retry to request
  final Duration timeRetry;

  ///whether cache image to local
  final bool cache;

  /// The URL from which the image will be fetched.
  final String url;

  /// The scale to place in the [ImageInfo] object of the image.
  final double scale;

  /// The HTTP headers that will be used with [HttpClient.get] to fetch image from network.
  final Map<String, String> headers;  

或者你也可以这样用

ExtendedImage.network(
                url,
                cache: true,
              ),

圆角,边框,圆形

ExtendedImage.network(
                url,
                width: ScreenUtil.instance.setWidth(400),
                height: ScreenUtil.instance.setWidth(400),
                fit: BoxFit.fill,
                cache: true,
                border: Border.all(color: Colors.red, width: 1.0),
                shape: boxShape,
                borderRadius: BorderRadius.all(Radius.circular(30.0)),
              ),

清除本地缓存,清除内存缓存,保存网络图片到相册

清除本地缓存,你可以选择清楚全部,也可以给一个时间(清除比如7天之前的)

// Clear the disk cache directory
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
flutter_image_editor是一个用于在Flutter应用程序中编辑图像的库。它提供了一组功能强大的图像编辑工具,可以使用它们来裁剪、旋转、调整尺寸和应用滤镜等操作。 首先,在使用flutter_image_editor之前,我们需要将其添加为项目的依赖项。我们可以在pubspec.yaml文件中添加以下行: ``` dependencies: flutter_image_editor: ^版本号 ``` 然后运行`flutter packages get`来获取库。 一旦我们添加了flutter_image_editor库,我们就可以开始使用它了。首先,我们需要导入库: ```dart import 'package:flutter_image_editor/flutter_image_editor.dart'; ``` 然后,我们可以使用ImageEditor类的实例来编辑图像。以下是使用flutter_image_editor的一些常见功能: 1. 裁剪图像: ```dart final result = await ImageEditor.cropImage( file.path, startX: 0, startY: 0, width: 200, height: 200, ); ``` 2. 旋转图像: ```dart final result = await ImageEditor.rotateImage( 90, // 旋转角度 file.path, ); ``` 3. 调整图像尺寸: ```dart final result = await ImageEditor.resizeImage( 500, // 新的宽度 500, // 新的高度 file.path, ); ``` 4. 应用滤镜: ```dart final result = await ImageEditor.applyFilter( ImageFilter.sepia, // 滤镜类型 file.path, ); ``` 这些只是flutter_image_editor支持的一些功能示例。根据您的需求,您还可以使用其他功能来编辑和处理图像。 最后,根据每种编辑操作的返回类型,您可以在Flutter应用程序中根据需要使用编辑后的图像结果。例如,您可以将它们显示在Image widget中,保存到设备上的文件中,或将其上传到服务器等等。 总结而言,flutter_image_editor是一个非常方便和强大的图像编辑库,它可以帮助我们在Flutter应用程序中轻松地实现各种图像编辑操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值