feat: link transit registration to boxing
This commit is contained in:
39
lib/services/registration_linking.dart
Normal file
39
lib/services/registration_linking.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pad_scanner/services/code_parser.dart';
|
||||
|
||||
const batchPaichaMismatchMessage = '批量凑箱仅支持同排产号产品,请移除不属于同一批次的总排号';
|
||||
|
||||
bool isTransitTarget(CodeType? locationType, String? locationCode) {
|
||||
return locationType == CodeType.locationTransit ||
|
||||
(locationCode?.startsWith('TRANS-') ?? false);
|
||||
}
|
||||
|
||||
String registrationSubmitLabel({
|
||||
required bool isTransitTarget,
|
||||
required bool isLocked,
|
||||
required int zongpaiCount,
|
||||
}) {
|
||||
if (!isTransitTarget) {
|
||||
return isLocked && zongpaiCount > 1 ? '批量上架($zongpaiCount 条)' : '确 认 上 架';
|
||||
}
|
||||
return isLocked && zongpaiCount > 1 ? '批量转运并凑箱($zongpaiCount 条)' : '转运并装箱';
|
||||
}
|
||||
|
||||
Color registrationSubmitColor({
|
||||
required bool canSubmit,
|
||||
required bool isTransitTarget,
|
||||
required Color primaryColor,
|
||||
}) {
|
||||
if (!canSubmit) return Colors.grey.shade300;
|
||||
return isTransitTarget ? Colors.orange : primaryColor;
|
||||
}
|
||||
|
||||
bool allSamePaicha(Iterable<String?> paichaNos) {
|
||||
String? first;
|
||||
for (final paichaNo in paichaNos) {
|
||||
if (paichaNo == null || paichaNo.isEmpty) return false;
|
||||
first ??= paichaNo;
|
||||
if (paichaNo != first) return false;
|
||||
}
|
||||
return first != null;
|
||||
}
|
||||
@@ -9,19 +9,24 @@ class ScanResult {
|
||||
}
|
||||
|
||||
class ScannerService {
|
||||
static const _eventChannel =
|
||||
EventChannel('com.example.pad_scanner/scan');
|
||||
|
||||
Stream<ScanResult>? _scanStream;
|
||||
static const _eventChannel = EventChannel('com.example.pad_scanner/scan');
|
||||
static Stream<ScanResult>? _sharedScanStream;
|
||||
|
||||
Stream<ScanResult> get scanResults {
|
||||
_scanStream ??= _eventChannel
|
||||
_sharedScanStream ??= _createSharedScanStream();
|
||||
return _sharedScanStream!;
|
||||
}
|
||||
|
||||
static Stream<ScanResult> _createSharedScanStream() {
|
||||
return _eventChannel
|
||||
.receiveBroadcastStream()
|
||||
.map((event) => event as Map)
|
||||
.map((event) => ScanResult(
|
||||
barcode: event['barcode'] as String? ?? '',
|
||||
codeType: event['codeType'] as String? ?? 'UNKNOWN',
|
||||
));
|
||||
return _scanStream!;
|
||||
.map(
|
||||
(event) => ScanResult(
|
||||
barcode: event['barcode'] as String? ?? '',
|
||||
codeType: event['codeType'] as String? ?? 'UNKNOWN',
|
||||
),
|
||||
)
|
||||
.asBroadcastStream();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user