From 960d92e51fb0a4914293663c8ec3c209cb661dbe Mon Sep 17 00:00:00 2001 From: Misaka Date: Thu, 7 May 2026 19:55:29 +0800 Subject: [PATCH] feat: add ScannerService with EventChannel Co-Authored-By: Claude Opus 4.6 --- lib/services/scanner_service.dart | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 lib/services/scanner_service.dart diff --git a/lib/services/scanner_service.dart b/lib/services/scanner_service.dart new file mode 100644 index 0000000..cb7a155 --- /dev/null +++ b/lib/services/scanner_service.dart @@ -0,0 +1,27 @@ +import 'dart:async'; +import 'package:flutter/services.dart'; + +class ScanResult { + final String barcode; + final String codeType; + + ScanResult({required this.barcode, required this.codeType}); +} + +class ScannerService { + static const _eventChannel = + EventChannel('com.example.pad_scanner/scan'); + + Stream? _scanStream; + + Stream get scanResults { + _scanStream ??= _eventChannel + .receiveBroadcastStream() + .map((event) => event as Map) + .map((event) => ScanResult( + barcode: event['barcode'] as String? ?? '', + codeType: event['codeType'] as String? ?? 'UNKNOWN', + )); + return _scanStream!; + } +}