eliasteeny / flutter_document_scanner

Document scanner plugin ported from react native to flutter
MIT License
38 stars 26 forks source link

Unexpected behavior. Enhancement request. #4

Open UlanNurmatov opened 3 years ago

UlanNurmatov commented 3 years ago

Hi. Thanks for the plugin. I have a few issues:

1) The cropped images are greyscale. Can we make it color?

2) I tried to use code from example app. The initial image capture and cropping works great. After that, the circular progress indicator doesn't disappear. "retry" text doesn't appear. Also a random image is taken without cropping.

3) Enhancement. Is there a way to manually start and and stop the rectangle detection?

Below is the code that I've slightly modified.

import 'dart:io';

import 'package:flutter/material.dart';

import 'package:document_scanner/document_scanner.dart';
import 'package:permission_handler/permission_handler.dart';

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

class _MyAppState extends State<MyAppp> {
  File scannedDocument;
  Future<PermissionStatus> cameraPermissionFuture;
  Future<Map<Permission, PermissionStatus>> statuses;
  @override
  void initState() {
    // cameraPermissionFuture = Permission.camera.request();
    // storagePermissionFuture = Permission.storage.request();
    _requestPermission();
    super.initState();
  }

  _requestPermission() {
    statuses = [
      Permission.camera,
      Permission.storage,
    ].request();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: FutureBuilder<Map<Permission, PermissionStatus>>(
            future: statuses,
            builder: (BuildContext context,
                AsyncSnapshot<Map<Permission, PermissionStatus>> snapshot) {
              if (snapshot.connectionState == ConnectionState.done) {
                bool allGranted = snapshot.data[Permission.camera] ==
                        PermissionStatus.granted &&
                    snapshot.data[Permission.storage] ==
                        PermissionStatus.granted;
                if (allGranted) {
                  return Stack(
                    children: <Widget>[
                      Column(
                        children: <Widget>[
                          Expanded(
                            child: scannedDocument != null
                                ? Image(
                                    image: FileImage(scannedDocument),
                                  )
                                : DocumentScanner(
                                    onDocumentScanned:
                                        (ScannedImage scannedImage) {
                                      print("document : " +
                                          scannedImage.croppedImage);

                                      setState(() {
                                        scannedDocument = scannedImage
                                            .getScannedDocumentAsFile();
                                        // imageLocation = image;
                                      });
                                    },
                                  ),
                          ),
                        ],
                      ),
                      scannedDocument != null
                          ? Positioned(
                              bottom: 20,
                              left: 0,
                              right: 0,
                              child: RaisedButton(
                                  child: Text("retry"),
                                  onPressed: () {
                                    setState(() {
                                      scannedDocument = null;
                                    });
                                  }),
                            )
                          : Container(),
                    ],
                  );
                } else
                  return Center(
                    child: Text("camera permission denied"),
                  );
              } else {
                return Center(
                  child: CircularProgressIndicator(),
                );
              }
            },
          )),
    );
  }
}
UlanNurmatov commented 3 years ago

Noticed the warning in Readme. Are you planning to bring customization back soon?

eliasteeny commented 3 years ago

Hello, you're welcome.

Yes, I'm planning to bring back customization, but my free time is very limited. Concerning the unexpected behavior, I'll try to resolve it asap. It would really help me if you can share the app's log when this behavior occurs.

UlanNurmatov commented 3 years ago

Here's a video where I test the plugin: https://youtu.be/HEzyGN9dLto

Below is the code that I simplified just to get the scanned image path. But my code doesn't work, the plugin works on its own.

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:document_scanner/document_scanner.dart';
import 'package:permission_handler/permission_handler.dart';

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

class _MyAppState extends State<MyAppp> {
  Future<PermissionStatus> cameraPermissionFuture;
  Future<Map<Permission, PermissionStatus>> statuses;
  File scannedDocument;
  @override
  void initState() {
    // cameraPermissionFuture = Permission.camera.request();
    // storagePermissionFuture = Permission.storage.request();
    _requestPermission();
    super.initState();
  }

  _requestPermission() {
    statuses = [
      Permission.camera,
      Permission.storage,
    ].request();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            appBar: AppBar(
              title: const Text('Plugin example app'),
            ),
            body: scannedDocument == null
                ? DocumentScanner(
                    onDocumentScanned: (ScannedImage scannedImage) {
                      setState(() {
                        scannedDocument =
                            scannedImage.getScannedDocumentAsFile();
                      });
                    },
                  )
                : Center(child: Text(scannedDocument.path))));
  }
}
UlanNurmatov commented 3 years ago

Hello, you're welcome.

Yes, I'm planning to bring back customization, but my free time is very limited. Concerning the unexpected behavior, I'll try to resolve it asap. It would really help me if you can share the app's log when this behavior occurs.

Any update? This is probably the best rectangle recognition plugin, would be great if it worked as expected.

eliasteeny commented 3 years ago

@UlanNurmatov try version 0.1.1, the unexpected behavior should be resolved.