mirror of
https://git.meshkee.com/applications/cssd.git
synced 2026-10-10 20:58:54 +03:30
Fix barcode scanner bug in add package select item
This commit is contained in:
+12
-19
@@ -43,18 +43,11 @@ class PackageProvider extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// var isDuplicateItem = false;
|
||||
changeItemVal(String value, int index) {
|
||||
for (var item in filteredItems!) {
|
||||
// if(itemValues.length > 1 && value != itemValues[index-1].text){
|
||||
if (item.udi_name == value) {
|
||||
itemValues[index].text = item.id;
|
||||
}
|
||||
// }else {
|
||||
// // isDuplicateItem = true;
|
||||
// print("it is a problem!!!!!!!!!!");
|
||||
// }
|
||||
|
||||
if (item.udi_name == value) {
|
||||
itemValues[index].text = item.id;
|
||||
}
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
@@ -85,12 +78,13 @@ class PackageProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
changeItemValByScan(String value, int index) {
|
||||
for (var item in filteredItems!) {
|
||||
if (item.udi == value) {
|
||||
changeItemValByScan(String value, int index) async {
|
||||
filteredItems?.forEach((item) {
|
||||
if (item.id == value) {
|
||||
itemValues[index].text = "${item.name} - ${item.udi}";
|
||||
}
|
||||
}
|
||||
print("item value : ${itemValues[index].text}");
|
||||
});
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -350,11 +344,10 @@ class PackageProvider extends ChangeNotifier {
|
||||
for (var item in testResultData['data']) {
|
||||
originalItems!.add(
|
||||
PackageResultObject(
|
||||
createdAt: item['created_at'],
|
||||
id: item['id'].toString(),
|
||||
name: item['name'],
|
||||
status: item['status']
|
||||
),
|
||||
createdAt: item['created_at'],
|
||||
id: item['id'].toString(),
|
||||
name: item['name'],
|
||||
status: item['status']),
|
||||
);
|
||||
}
|
||||
pageNumber += 1;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:cssd/models/item_model.dart';
|
||||
import 'package:cssd/providers/packages.dart';
|
||||
import 'package:cssd/utils/scan.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -23,6 +22,7 @@ class AddItemBox extends StatelessWidget {
|
||||
|
||||
final double _deviceBlockSize;
|
||||
final TextEditingController values;
|
||||
|
||||
// final List<Map<String, dynamic>> vals;
|
||||
final List<String> vals;
|
||||
|
||||
@@ -31,6 +31,7 @@ class AddItemBox extends StatelessWidget {
|
||||
final String text;
|
||||
final Color? iconColor;
|
||||
final bool hasRemoveButton;
|
||||
|
||||
// final List<ItemResultObject> filteredItems;
|
||||
// final String scanUdi;
|
||||
|
||||
@@ -117,30 +118,34 @@ class AddItemBox extends StatelessWidget {
|
||||
height: 70,
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 0),
|
||||
child: Consumer<PackageProvider>(builder: (context, packageProvider, _) {
|
||||
return TextFormField(
|
||||
controller: values,
|
||||
validator: (val) {
|
||||
if (val!.isEmpty) {
|
||||
return 'Item required!';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
contentPadding: EdgeInsets.only(
|
||||
bottom: 12,
|
||||
child: Consumer<PackageProvider>(
|
||||
builder: (context, packageProvider, _) {
|
||||
return TextFormField(
|
||||
controller:
|
||||
packageProvider.itemValues[index],
|
||||
validator: (val) {
|
||||
if (val!.isEmpty) {
|
||||
return 'Item required!';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
contentPadding: EdgeInsets.only(
|
||||
bottom: 12,
|
||||
),
|
||||
isDense: true,
|
||||
),
|
||||
isDense: true,
|
||||
),
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.black,
|
||||
fontSize: 4 * _deviceBlockSize,
|
||||
),
|
||||
);
|
||||
},),
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.black,
|
||||
fontSize: 4 * _deviceBlockSize,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
isDense: true,
|
||||
// selectedItemBuilder: packageProvider.itemValues[index].value,
|
||||
items: vals.map((val) {
|
||||
return new DropdownMenuItem<String>(
|
||||
enabled: isEnabled,
|
||||
@@ -166,7 +171,7 @@ class AddItemBox extends StatelessWidget {
|
||||
InkWell(
|
||||
onTap: () {
|
||||
scan().then(
|
||||
(String result) {
|
||||
(String result) async {
|
||||
if (result == 'cancel') {
|
||||
print('cancel');
|
||||
} else if (result == 'error') {
|
||||
@@ -174,8 +179,8 @@ class AddItemBox extends StatelessWidget {
|
||||
} else if (result == 'access') {
|
||||
print('access');
|
||||
} else {
|
||||
print(result);
|
||||
Provider.of<PackageProvider>(context,
|
||||
await Provider.of<PackageProvider>(
|
||||
context,
|
||||
listen: false)
|
||||
.changeItemValByScan(result, index);
|
||||
isEnabled = false;
|
||||
|
||||
@@ -41,7 +41,15 @@ class PackageAddSaveButton extends StatelessWidget {
|
||||
}
|
||||
List<String> items = [];
|
||||
for (TextEditingController item in itemValues) {
|
||||
items.add(item.text);
|
||||
print(item.text);
|
||||
if (item.text.toString().contains(" ")) {
|
||||
packageProvider.filteredItems?.forEach((element) {
|
||||
if (element.udi_name.toString() == item.text.toString()) {
|
||||
items.add(element.id.toString());
|
||||
}
|
||||
});
|
||||
} else
|
||||
items.add(item.text);
|
||||
}
|
||||
items = items.toSet().toList();
|
||||
await Provider.of<PackageProvider>(context, listen: false)
|
||||
|
||||
Reference in New Issue
Block a user