Flutter 文档扫描器

Pub build License: MIT


插件和 OpenCV

Demo


用法

首先,在你的 pubspec.yaml 文件中添加 flutter_document_scanner 作为 依赖

示例

导入库。

import 'package:flutter_document_scanner/flutter_document_scanner.dart';

初始化 DocumentScannerController

  final _controller = DocumentScannerController();

显示组件

DocumentScanner(
  controller: _controller,
  onSave: (Uint8List imageBytes) {
    print("image bytes: $imageBytes");
  },
);

Controller Document 使用

操作

_controller.takePhoto(
  minContourArea: 80000.0,
);

_controller.cropPhoto();

_controller.applyFilter(FilterType.gray);

_controller.savePhotoDocument();

_controller.changePage(AppPages.cropPhoto);

可以监听更改

_controller.statusTakePhotoPage.listen((AppStatus event) {
  print("Changes when taking the picture");
  print("[initial, loading, success, failure]");
});


_controller.statusCropPhoto.listen((AppStatus event) {
  print("Changes while cutting the image and adding warp perspective");
  print("[initial, loading, success, failure]");
});


_controller.statusEditPhoto.listen((AppStatus event) {
  print("Changes when editing the image (applying filters)");
  print("[initial, loading, success, failure]");
});


_controller.currentFilterType.listen((FilterType event) {
  print("Listen to the current filter applied on the image");
  print("[ natural, gray, eco]");
});


_controller.statusSavePhotoDocument.listen((AppStatus event) {
  print("Changes while the document image is being saved");
  print("[initial, loading, success, failure]");
});

自定义

相机

DocumentScanner(
  controller: _controller,
  onSave: (Uint8List imageBytes) {
    print("image bytes: $imageBytes");
  },
  resolutionCamera: ResolutionPreset.high,
  initialCameraLensDirection: CameraLensDirection.front,
);

页面过渡

DocumentScanner(
  controller: _controller,
  onSave: (Uint8List imageBytes) {
    print("image bytes: $imageBytes");
  },
  pageTransitionBuilder: (child, animation) {
    final tween = Tween(begin: 0.0, end: 1.0);

    final curvedAnimation = CurvedAnimation(
      parent: animation,
      curve: Curves.easeOutCubic,
    );

    return FadeTransition(
      opacity: tween.animate(curvedAnimation),
      child: child,
    );
  },
);

通用样式

属性列表 在此

拍照页面

属性列表 在此

裁剪图像页面

属性列表 在此

编辑图像页面

属性列表 在此

GitHub

查看 Github