docutain_sdk 0.0.1-beta.5 copy "docutain_sdk: ^0.0.1-beta.5" to clipboard
docutain_sdk: ^0.0.1-beta.5 copied to clipboard

The best document scanner and data extraction sdk you can get.

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:open_file/open_file.dart';
import 'package:path_provider/path_provider.dart';
import 'package:docutain_sdk/docutain_sdk.dart';
import 'package:docutain_sdk/docutain_sdk_ui.dart';
import 'package:docutain_sdk/docutain_sdk_document.dart';

void main() {
  runApp(const MaterialApp(home: MyApp()));
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool _isDocutainPluginInitialized = false;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    initDocutainSdk();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text('DocutainSDK'),
        ),
        body: Center(
          child:
          ElevatedButton(
              onPressed: () async {
                //do not access sdk methods if it is not yet successfully initialized
                if(!_isDocutainPluginInitialized){
                  //await _showMyDialog("Error", "Docutain SDK not yet initialized.");
                  _showSnackbar("Docutain SDK not initialized. Reason:\n${await DocutainSdk.getLastError()}");
                  return;
                }

                var scanConfig = DocumentScannerConfiguration();
                //optionally enable switching capture mode
                //scanConfig.allowCaptureModeSetting = true;

                //start the document scanner and wait for the result
                //true if user finished the scan process successfully, false if user canceled
                bool rcScan = await DocutainSdkUi.scanDocument(scanConfig);
                if(!rcScan){
                  _showSnackbar("User canceled scan process.");
                  return;
                }

                //get the application documents directory where we want to save the pdf
                final directory = await getApplicationDocumentsDirectory();

                //generate the pdf from the scanned document
                //returns the file if pdf was successfully generated, returns null if pdf creation failed
                File? pdfFile = await DocutainSdkDocument.writePDF(
                    directory.path, "testPDF");

                if (pdfFile != null) {
                  //open the generated pdf file for demonstration purposes
                  OpenFile.open(pdfFile.path);
                } else{
                  //pdf creation failed, get the last error
                  _showSnackbar("PDF creation failed. Reason:\n${await DocutainSdk.getLastError()}");
                }
              },
              child: const Text('START SCAN')),
        ),
      );
  }

  void initDocutainSdk() async {
    //initialize the sdk with a sample key
    bool isDocutainPluginInitialized = await DocutainSdk.initSDK(
        "<YOUR_LICENSE_KEY_HERE>");
    if(!_isDocutainPluginInitialized){
      //get the last error message
      String error = await DocutainSdk.getLastError();
      //implement handling to avoid accessing Docutain SDK when it is not initialized
    }

    if (!mounted) return;

    setState(() {
      _isDocutainPluginInitialized = isDocutainPluginInitialized;
    });
  }

  void _showSnackbar(String message){
    SnackBar snackBar = SnackBar(
      content: Text(message),
    );

    ScaffoldMessenger.of(context).showSnackBar(snackBar);
  }
}
6
likes
0
pub points
69%
popularity

Publisher

verified publisherdocutain.de

The best document scanner and data extraction sdk you can get.

Homepage

License

unknown (LICENSE)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on docutain_sdk