docutain_sdk 0.0.1-beta.3 copy "docutain_sdk: ^0.0.1-beta.3" to clipboard
docutain_sdk: ^0.0.1-beta.3 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;
                }

                //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();
                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);
  }
}
11
likes
0
pub points
71%
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