Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior. Enhancement request. #4

Open
UlanNurmatov opened this issue Feb 11, 2021 · 5 comments
Open

Unexpected behavior. Enhancement request. #4

UlanNurmatov opened this issue Feb 11, 2021 · 5 comments

Comments

@UlanNurmatov
Copy link

UlanNurmatov commented Feb 11, 2021

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
Copy link
Author

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

@eliasteeny
Copy link
Owner

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
Copy link
Author

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
Copy link
Author

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants