mlkit_document_scanner 0.0.5 copy "mlkit_document_scanner: ^0.0.5" to clipboard
mlkit_document_scanner: ^0.0.5 copied to clipboard

PlatformAndroid

Flutter plugin bringing MLKit Document Scanner to Flutter. Available only for Android.

example/lib/main.dart

import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:mlkit_document_scanner/mlkit_document_scanner.dart';
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

final class _MyAppState extends State<MyApp> {
  final MlkitDocumentScannerPlugin _mlkitDocumentScannerPlugin =
      MlkitDocumentScannerPlugin(token: Object());
  late final Stream<List<Uint8List>?> _jpegDocumentStream;
  late final Stream<Uint8List?> _pdfDocumentStream;

  @override
  void initState() {
    super.initState();
    _jpegDocumentStream = _mlkitDocumentScannerPlugin.jpegScanResults;
    _pdfDocumentStream = _mlkitDocumentScannerPlugin.pdfScanResults;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SafeArea(
          minimum: const EdgeInsets.all(16.0),
          child: ListView(
            children: [
              TextButton(
                onPressed: () =>
                    _mlkitDocumentScannerPlugin.startDocumentScanner(
                  maximumNumberOfPages: 1,
                  galleryImportAllowed: true,
                  scannerMode: MlkitDocumentScannerMode.full,
                  resultMode: DocumentScannerResultMode.both,
                ),
                child: const Text('Start scanner'),
              ),
              StreamBuilder(
                stream: _jpegDocumentStream,
                builder: (BuildContext context,
                    AsyncSnapshot<List<Uint8List>?> data) {
                  return data.hasData && data.data != null
                      ? ListView(
                          shrinkWrap: true,
                          children: data.data!
                              .map((item) => Image.memory(item))
                              .toList(),
                        )
                      : const Text('No JPEG data yet');
                },
              ),
              StreamBuilder(
                stream: _pdfDocumentStream,
                builder:
                    (BuildContext context, AsyncSnapshot<Uint8List?> data) {
                  return data.hasData && data.data != null
                      ? SizedBox(
                          height: MediaQuery.of(context).size.height - 32,
                          child: SfPdfViewer.memory(data.data!),
                        )
                      : const Text('No PDF data yet');
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}
4
likes
160
pub points
61%
popularity

Publisher

unverified uploader

Flutter plugin bringing MLKit Document Scanner to Flutter. Available only for Android.

Repository (GitHub)
View/report issues

Topics

#machine-learning #mlkit #document-scanner

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on mlkit_document_scanner