onCollectStockScan method
Implementation
Future onCollectStockScan() async {
if (selectedScanType.value == "Single") {
String iccid = singleScanController.text;
if (iccid.isEmpty) {
Helper.assetSuccessDialog(
Get.context!,
"Failed to add asset.",
"Enter valid iccid",
const AssetImage(
"assets/images/failed.png",
));
return;
}
singleScanController.clear();
if (scannedIccidList.contains(iccid) ||
prevScannedIccidList.contains(iccid)) {
Helper.assetSuccessDialog(
Get.context!,
"Failed to add asset.",
"Id already added!",
const AssetImage(
"assets/images/failed.png",
));
return;
}
SingleScannedModel? singleData;
for (final data in availableSingleList) {
if (data.iccid == iccid) {
singleData = data;
break;
}
}
if (singleData == null) {
debugPrint("scanned iccid is not available");
Helper.assetSuccessDialog(
Get.context!,
"Failed to add asset.",
"Id not found",
const AssetImage(
"assets/images/failed.png",
));
} else {
addAssetToProduct(singleId: iccid, singleData: singleData);
}
} else if (selectedScanType.value == "Range") {
String start = rangeStartScanController.value.text;
String end = rangeEndScanController.value.text;
if (start.isEmpty || end.isEmpty) {
Helper.assetSuccessDialog(
Get.context!,
"Failed to add asset.",
"Please enter start and end range",
const AssetImage(
"assets/images/failed.png",
));
return;
}
rangeStartScanController.value.clear();
rangeEndScanController.value.clear();
if (int.parse(start) > int.parse(end)) {
Helper.assetSuccessDialog(
Get.context!,
"Failed to add asset.",
"End range should be greater than start range",
const AssetImage(
"assets/images/failed.png",
));
return;
}
bool someAssetsAlreadyScanned = false;
for (final data in scannedIccidList) {
if (int.parse(start) <= int.parse(data) &&
int.parse(data) <= int.parse(end)) {
someAssetsAlreadyScanned = true;
break;
}
}
if (someAssetsAlreadyScanned) {
Helper.assetSuccessDialog(
Get.context!,
"Failed to add asset.",
"Please use different range, some assets are already scanned",
const AssetImage(
"assets/images/failed.png",
));
return;
}
bool isStartAvailable = false;
bool isEndAvailable = false;
for (final data in availableSingleList) {
if (data.iccid == start) {
isStartAvailable = true;
break;
}
}
for (final data in availableSingleList) {
if (data.iccid == end) {
isEndAvailable = true;
break;
}
}
if (isStartAvailable && isEndAvailable) {
List<SingleScannedModel> rangeItems = [];
for (final data in availableSingleList) {
if (int.parse(start) <= int.parse(data.iccid!) &&
int.parse(data.iccid!) <= int.parse(end)) {
rangeItems.add(data);
}
}
addAssetToProduct(
startRange: start,
endRange: end,
rangeAssets: rangeItems,
);
} else {
debugPrint("scanned range is not available");
Helper.assetSuccessDialog(
Get.context!,
"Failed to add asset.",
"Range not found",
const AssetImage(
"assets/images/failed.png",
));
}
}
debugPrint("scannedAssets : $scannedIccidList");
}