head_image_cropper 3.1.0 copy "head_image_cropper: ^3.1.0" to clipboard
head_image_cropper: ^3.1.0 copied to clipboard

A picture cutting part of flutter, which supports square picture and round picture preview. Suitable for fixed size image clipping. Such as cutting the head

example/lib/main.dart

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 _controller = CropperController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        actions: <Widget>[
          TextButton(
            child: Text("保存"),
            style: ButtonStyle(foregroundColor: MaterialStateProperty.all(Colors.white)),
            onPressed: () {
              _controller.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(
          AssetImage("images/test.webp"),
          controller: _controller,
        ),
      ),
    );
  }
}

class ShowImage extends StatefulWidget {
  final Uint8List data;

  const ShowImage({Key? key, required 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),
    );
  }
}
11
likes
90
pub points
70%
popularity

Publisher

unverified uploader

A picture cutting part of flutter, which supports square picture and round picture preview. Suitable for fixed size image clipping. Such as cutting the head

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter, flutter_web_plugins

More

Packages that depend on head_image_cropper