PluginTechWinzad / plaser_scanner

MIT License
1 stars 0 forks source link

onListenerScanner doesn't return anything #2

Open SamsonCy opened 9 months ago

SamsonCy commented 9 months ago

Hi,

i using Urovo DT50, below is my code.

Screenshot 2024-01-23 at 4 13 21 PM

FINE: Pub 2.19.2 [✓] Flutter (Channel stable, 3.7.3, on macOS 13.5.1 22G90 darwin-x64, locale en-GB) • Flutter version 3.7.3 on channel stable at /Users/unknownmac/fvm/versions/3.7.3 • Upstream repository https://github.com/flutter/flutter.git • Framework revision 9944297138 (12 months ago), 2023-02-08 15:46:04 -0800 • Engine revision 248290d6d5 • Dart version 2.19.2 • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) • Android SDK at /Users/unknownmac/Library/Android/sdk • Platform android-33, build-tools 33.0.0 • ANDROID_HOME = /Users/unknownmac/Android/Sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14B47b • CocoaPods version 1.12.0

[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.77.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.80.0

[✓] Connected device (3 available) • DT50 (mobile) • 01602321013501 • android-arm64 • Android 11 (API 30) • macOS (desktop) • macos • darwin-x64 • macOS 13.5.1 22G90 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 120.0.6099.234

[✓] HTTP Host Availability • All required HTTP hosts are available

• No issues found! IO : Writing 7961 characters to text file /Users/unknownmac/.pub-cache/log/pub_log.txt. MSG : Logs written to /Users/unknownmac/.pub-cache/log/pub_log.txt

0352972441 commented 8 months ago
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:laser_scanner/laser_scanner.dart';
import 'package:laser_scanner/model/scan_result_model.dart';
import 'package:laser_scanner/utils/enum_utils.dart';

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

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

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

class _MyAppState extends State<MyApp> {
  final _laserScannerPlugin = LaserScanner();
  ScanResultModel scanResultModel = ScanResultModel();
  StreamSubscription? subscription;

  @override
  void initState() {
    super.initState();
    _openScanner();
  }

  @override
  void dispose() {
    super.dispose();
    subscription?.cancel();
  }

  Future<void> _openScanner() async {
    await _laserScannerPlugin.openScanner(
      captureImageShow: true,
    );
    _setTrigger();
    _getTrigger();
    await onListenerScanner();
  }

  Future<void> onListenerScanner() async {
    subscription = await _laserScannerPlugin.onListenerScanner(onListenerResultScanner: (value) {
      setState(() {
        scanResultModel = value ?? ScanResultModel();
      });
      _laserScannerPlugin.stopDecode();
    });
  }

  void _setTrigger() {
    _laserScannerPlugin.setTrigger(triggering: Triggering.HOST);
  }

  void _getTrigger() async {
    await _laserScannerPlugin.getTriggerMode();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Laser scanner'),
        ),
        body: Center(
          child: Column(
            children: [
              Text('barcode: ${scanResultModel.barcode}'),
              const SizedBox(
                height: 10,
              ),
              Text('barcodeStr: ${scanResultModel.barcodeStr}'),
              const SizedBox(
                height: 10,
              ),
              Text('bytesToHexString: ${scanResultModel.bytesToHexString}'),
              const SizedBox(
                height: 10,
              ),
              Text('length: ${scanResultModel.length}'),
              const SizedBox(
                height: 100,
              ),
              if (scanResultModel.image != null)
                SizedBox(
                    height: 200, width: MediaQuery.of(context).size.width, child: Image.memory(scanResultModel.image!)),
              const SizedBox(
                height: 100,
              ),
              MaterialButton(
                onPressed: () {
                  _laserScannerPlugin.startDecode();
                },
                child: const Text("Scan"),
              )
            ],
          ),
        ),
      ),
    );
  }
}

Please try running this code.

nnasibova commented 1 month ago
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:laser_scanner/laser_scanner.dart';
import 'package:laser_scanner/model/scan_result_model.dart';
import 'package:laser_scanner/utils/enum_utils.dart';

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

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

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

class _MyAppState extends State<MyApp> {
  final _laserScannerPlugin = LaserScanner();
  ScanResultModel scanResultModel = ScanResultModel();
  StreamSubscription? subscription;

  @override
  void initState() {
    super.initState();
    _openScanner();
  }

  @override
  void dispose() {
    super.dispose();
    subscription?.cancel();
  }

  Future<void> _openScanner() async {
    await _laserScannerPlugin.openScanner(
      captureImageShow: true,
    );
    _setTrigger();
    _getTrigger();
    await onListenerScanner();
  }

  Future<void> onListenerScanner() async {
    subscription = await _laserScannerPlugin.onListenerScanner(onListenerResultScanner: (value) {
      setState(() {
        scanResultModel = value ?? ScanResultModel();
      });
      _laserScannerPlugin.stopDecode();
    });
  }

  void _setTrigger() {
    _laserScannerPlugin.setTrigger(triggering: Triggering.HOST);
  }

  void _getTrigger() async {
    await _laserScannerPlugin.getTriggerMode();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Laser scanner'),
        ),
        body: Center(
          child: Column(
            children: [
              Text('barcode: ${scanResultModel.barcode}'),
              const SizedBox(
                height: 10,
              ),
              Text('barcodeStr: ${scanResultModel.barcodeStr}'),
              const SizedBox(
                height: 10,
              ),
              Text('bytesToHexString: ${scanResultModel.bytesToHexString}'),
              const SizedBox(
                height: 10,
              ),
              Text('length: ${scanResultModel.length}'),
              const SizedBox(
                height: 100,
              ),
              if (scanResultModel.image != null)
                SizedBox(
                    height: 200, width: MediaQuery.of(context).size.width, child: Image.memory(scanResultModel.image!)),
              const SizedBox(
                height: 100,
              ),
              MaterialButton(
                onPressed: () {
                  _laserScannerPlugin.startDecode();
                },
                child: const Text("Scan"),
              )
            ],
          ),
        ),
      ),
    );
  }
}

Please try running this code.

this one does not work too

nnasibova commented 1 month ago

@0352972441 can you help with it?