flutter_smart_cropper 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 74

flutter_smart_cropper #

A Flutter plugin use to crop largest rectangle object in picture.

用于裁剪出图像中的最大的矩形,例如身份证,名片,文档的识别

  • 矩形识别iOS端使用Photos.framework中的边缘识别器,
  • Android使用的是pqpo的SmartCropper,底层用OpenCV实现

需要配合image和image_picker包使用

更多使用场景参考pqpo的SmartCropper

使用 #

flutter版本要求: 1.5

在pubspec.yaml添加依赖

flutter_smart_cropper: ^0.1.2

在执行"flutter packages get"后,您可以查看包中的example,了解如何使用它。

检测最大矩形代码

    var imageFile = await ImagePicker.pickImage(source: ImageSource.gallery);
    String file = imageFile.path;
    RectPoint rectPoint = await FlutterSmartCropper.detectImageRect(file);

0.1.2 - 2019-08-17 #

  • Merge PR from cputoaster for find dependency aar
  • Android: not resize image
  • iOS: Support Swift 4.2

0.1.1 - 2019-06-04 #

  • 文档更新

0.1.0 - 2019-06-03 #

  • 初步实现功能

example/lib/main.dart

import 'dart:typed_data';

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

import 'package:flutter/services.dart';
import 'package:flutter_smart_cropper/flutter_smart_cropper.dart';
import 'package:image_picker/image_picker.dart';
import 'crop_image.dart';

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

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyApp()
    );
  }
}


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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await FlutterSmartCropper.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Plugin example app'),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'Click + Icon to choose Image',
            ),
            bytes!=null ? Image.memory(bytes):Icon(Icons.error),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: toCropImage,
        tooltip: 'Choose Image',
        child: Icon(Icons.add),
      ), //
    );
  }
  Uint8List bytes;
  toCropImage() async {
//     ByteBuffer data = await FlutterSmartCropper.cropImage();
//     bytes = Uint8List.view(data);
//     setState(() {
//
//     });
    var imageFile = await ImagePicker.pickImage(source: ImageSource.gallery);
    String file = imageFile.path;
    RectPoint rectPoint = await FlutterSmartCropper.detectImageRect(file);

    var bts = await Navigator.push(context, MaterialPageRoute(builder: (BuildContext context)=>CropImage(file, rectPoint)));
    if (bts != null) {
      setState(() {
        bytes = bts;
      });
    }
  }



}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_smart_cropper: ^0.1.2

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:flutter_smart_cropper/flutter_smart_cropper.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
47
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
74
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
image ^2.1.3
image_picker ^0.6.0+8