fluttervisionsdkplugin 0.0.4 copy "fluttervisionsdkplugin: ^0.0.4" to clipboard
fluttervisionsdkplugin: ^0.0.4 copied to clipboard

A Flutter plugin package for integrating the Flutter Vision SDK into your Flutter application for scanning Barcodes and QrCodes

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:fluttervisionsdkplugin/fluttervisionsdkplugin.dart';

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

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

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

class _MyAppState extends State<MyApp> {
// pr
  String scannedCode = '';
  String detectedType = '';
  String scanErrorMessage = '';
  bool isManualCaptureMode = false;

  bool shouldDisplayFocusImage = false;

  List<String> receivedCodes = [];

  void _onScanError(String errorMessage) {
    print('Scan Error: $errorMessage');

    setState(() {
      scanErrorMessage = errorMessage;
    });
  }

  void updateReceivedCodes(List<String> codes) {
    setState(() {
      receivedCodes = codes;
    });
  }

  void updateCaptureMode(bool isManual) {
    setState(() {
      isManualCaptureMode = isManual;
    });
  }

  void updateScannedCode(String code) {
    setState(() {
      scannedCode = code;
    });
  }

  void onDetected(String type) {
    setState(() {
      detectedType = type;
    });
  }

  void _onCodesReceived(List<String> codes) {
    updateReceivedCodes(codes);

    if (codes.isNotEmpty) {
      updateScannedCode(codes.first);
    } else {
      updateScannedCode('');
    }
  }

  void _onDetectionResult(
      bool textDetected, bool barCodeDetected, bool qrCodeDetected) {
    print('Text Detected: $textDetected');
    print('Barcode Detected: $barCodeDetected');
    print('QR Code Detected: $qrCodeDetected');

    if (!barCodeDetected && !qrCodeDetected) {
      // Handle the case when none of the expected codes are detected
      _onScanError('No valid code detected');
    }
  }

  void _onOCRImagesReceived(Map<String, dynamic> scanResult) {
    print(scanResult);
  }

  void _changeCaptureMode(String mode) {
    print('Changing Capture Mode to: $mode');
  }

  void _changeScanMode(String mode) {
    print('Changing Scan Mode to: $mode');
  }

  void _capture() {
    print('Capturing Photo');
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Stack(
          children: [
            NativeViewWidget(
                onScanError: _onScanError,
                onCodesReceived: _onCodesReceived,
                onDetectionResult: _onDetectionResult,
                onOCRImagesReceived: _onOCRImagesReceived,
                shouldDisplayFocusImage: true,
                shouldScanInFocusImageRect: true,
                onDetected: onDetected,
                isTextIndicationOn: true,
                isBarCodeOrQRCodeIndicationOn: true,
                selectionTintColor: 'white',
                imageTintColor: 'white',
                codeDetectionConfidence: 0.5,
                sessionPreset: 'high',
                nthFrameToProcess: 10,
                captureMode: 0,
                captureType: 0,
                scanMode: 0,
                focusImage: '',
                focusImageRect: const {
                  'x': 0,
                  'y': 0,
                  'height': 0,
                  'width': 0,
                }),
            Positioned(
              left: 0,
              right: 0,
              bottom: 0,
              child: Padding(
                padding: const EdgeInsets.all(16.0),
                child: Container(
                  alignment: Alignment.bottomCenter,
                  width: double.infinity,
                  color: Colors.white,
                  padding: const EdgeInsets.all(16),
                  child: Column(
                    children: [
                      Text(
                        'Detected Type: $detectedType',
                        style:
                            const TextStyle(color: Colors.black, fontSize: 16),
                      ),
                      Text(
                        'Scanned Code: $scannedCode',
                        style:
                            const TextStyle(color: Colors.black, fontSize: 16),
                      ),
                      ElevatedButton(
                        onPressed: () {
                          const NativeViewWidget()
                              .onPressChangeCaptureMode('auto');
                        },
                        child: const Text('Change Capture Mode to Auto'),
                      ),
                      ElevatedButton(
                        onPressed: () {
                          const NativeViewWidget()
                              .onPressChangeCaptureMode('manual');
                          updateCaptureMode(true);
                        },
                        child: const Text('Change Capture Mode to Manual'),
                      ),
                      ElevatedButton(
                        onPressed: () {
                          const NativeViewWidget()
                              .onPressChangeScanMode('qrcode');
                        },
                        child: const Text('Change Scan Mode to QR Code'),
                      ),
                      ElevatedButton(
                        onPressed: () {
                          const NativeViewWidget()
                              .onPressChangeScanMode('barcode');
                        },
                        child: const Text('Change Scan Mode to Barcode'),
                      ),
                      ElevatedButton(
                        onPressed: () {
                          const NativeViewWidget().onPressChangeScanMode('ocr');
                        },
                        child: const Text('Change Scan Mode to OCR'),
                      ),
                      if (isManualCaptureMode)
                        ElevatedButton(
                          onPressed: () {
                            {
                              // Capture photo in manual mode when barcode or QR code is detected
                              const NativeViewWidget().onPressCapture();
                            }
                          },
                          child: const Text('Capture Manual Photo'),
                        ),
                    ],
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
2
likes
0
points
891
downloads

Publisher

verified publisherpackagex.io

Weekly Downloads

A Flutter plugin package for integrating the Flutter Vision SDK into your Flutter application for scanning Barcodes and QrCodes

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface

More

Packages that depend on fluttervisionsdkplugin