head_image_cropper 2.0.7

  • Readme
  • Changelog
  • Example
  • Installing
  • 65

使用 基于canvas撸的一个 Flutter头像裁剪控件

  • TODO:单指移动,双指移动、缩放、旋转
  • TODO:左键移动
  • TODO:滚轮旋转
  • TODO:左键+滚轮缩放

输入图片说明 输入图片说明

属性 backBoxSize 背景方格大小 默认值:10

backBoxColor0 背景方格颜色0 默认值:Colors.grey

backBoxColor1  背景方格颜色1 默认值:Colors.white

outWidth 输出图片宽度 默认值:256

outHeight 输出图片高度 默认值:256

maskColor 蒙板颜色 默认值:#00000080

maskPadding 蒙板内边距 默认值:20

lineWidth 预览框线宽 默认值:3

lineColor 预览框颜色 默认值:Colors.white

isArc 是否是圆形 默认值:true

round 预览框圆色 默认值:8

limitations 限制位置和尺寸 默认值:false

image 输入图片源

方法

outImage() 返回裁剪后的图片

使用 在pubspec.yaml文件中添加

dependencies:
  cropperimage:
    git:
      url: https://gitee.com/wskfjt/flutterhead_clipping_control

样例:


import 'package:flutter/material.dart';
import 'package:head_image_cropper/head_image_cropper.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State {
  var _cropperKey = GlobalKey();

  ImageProvider _image;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          actions: <Widget>[
            FlatButton(
              child: Text("保存"),
              onPressed: () {
                (_cropperKey.currentContext as CropperImageElement).outImage().then((image) {
                  //保存或上传代码
                });
              },
            )
          ],
        ),
        body: Container(
          padding: EdgeInsets.all(50),
          child: CropperImage(
            NetworkImage("http://n.sinaimg.cn/sinacn12/564/w1920h1044/20181111/69c3-hnstwwq4987218.jpg"),
            key: _cropperKey,
          ),
        ),
      ),
    );
  }
}

[0.0.1] - TODO: Add release date. #

  • TODO: Describe initial release.

[1.0.0] - TODO: Add release date. #

  • TODO: 简化代码。修改BUG.

[2.0.0] - TODO: Add release date. #

  • TODO: 重写代码.
  • TODO:添加鼠标支持
  • TODO:左键移动
  • TODO:滚轮旋转
  • TODO:左键+滚轮缩放
  • TODO:添加尺寸限制功能

[2.0.3] - TODO: Add release date. #

  • 修改BUG.##

[2.0.4] - TODO: Add release date.

  • 格式化代码.

[2.0.5] - TODO: Add release date.

  • 修改WEB端的BUG.

[2.0.7] - 2020/05/11

  • 修改Web端不能输出bytes的BUG

example/lib/main.dart

import 'dart:io';
import 'dart:typed_data';
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:head_image_cropper/head_image_cropper.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Home(),
    );
  }
}

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  var _cropperKey = GlobalKey();

  ImageProvider _image;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        actions: <Widget>[
          FlatButton(
            child: Text("保存"),
            onPressed: () {
              (_cropperKey.currentContext as CropperImageElement).outImage().then((image) async {
                //保存或上传代码
                var bytes = (await (image.toByteData(format: ImageByteFormat.png))).buffer.asUint8List();

                Navigator.of(context).push(MaterialPageRoute(builder: (context) {
                  return ShowImage(
                    data: bytes,
                  );
                }));
//                  File("path").writeAsBytesSync(bytes);
              });
            },
          )
        ],
      ),
      body: Container(
        padding: EdgeInsets.all(50),
        child: CropperImage(
          NetworkImage("http://n.sinaimg.cn/sinacn12/564/w1920h1044/20181111/69c3-hnstwwq4987218.jpg"),
          key: _cropperKey,
        ),
      ),
    );
  }
}

class ShowImage extends StatefulWidget {
  final Uint8List data;

  const ShowImage({Key key, this.data}) : super(key: key);

  @override
  _ShowImageState createState() => _ShowImageState();
}

class _ShowImageState extends State<ShowImage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("裁剪效果"),
      ),
      body: Image.memory(widget.data),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  head_image_cropper: ^2.0.7

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:head_image_cropper/head_image_cropper.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
32
Health:
Code health derived from static analysis. [more]
95
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
65
Learn more about scoring.

We analyzed this package on Jul 10, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform android

Because:

  • package:head_image_cropper/head_image_cropper.dart that declares support for platforms: web

Package does not support Flutter platform ios

Because:

  • package:head_image_cropper/head_image_cropper.dart that declares support for platforms: web

Package does not support Flutter platform linux

Because:

  • package:head_image_cropper/head_image_cropper.dart that declares support for platforms: web

Package does not support Flutter platform macos

Because:

  • package:head_image_cropper/head_image_cropper.dart that declares support for platforms: web

Package does not support Flutter platform windows

Because:

  • package:head_image_cropper/head_image_cropper.dart that declares support for platforms: web

Package not compatible with SDK dart

Because:

  • head_image_cropper that is a package requiring null.

Health issues and suggestions

Fix lib/src/cropper_image_web_out.dart. (-5 points)

Analysis of lib/src/cropper_image_web_out.dart reported 1 warning:

line 50 col 32: Parameters can't override default values, this method overrides 'Image.toByteData' where 'format' has a different value.

Format lib/src/cropper_image_out.dart.

Run flutter format to format lib/src/cropper_image_out.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
flutter_web_plugins 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test