I have a textfield in flutter and in that texfield I have a button where I have put the scan function where I scan barcode and pass result as argument to the exact screen where I have button for scanning.. the data gets saved screen doesn't update..
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 70,
width: double.maxFinite,
color: Color.fromARGB(153, 142, 255, 146),
child: TextButton(
onPressed: () {
stockInController.scan();
},
child: Align(
alignment: Alignment.centerLeft,
child: Row(
children: [
Expanded(
child: Text(selectedProducts!.isEmpty
? 'Select Product'
: selectedProducts!.join(
', ')), // Display selected product or placeholder
),
IconButton(
onPressed: () => stockInController.scan(),
icon: Icon(Icons.barcode_reader),
),
],
),
),
),
),
),
List<String?>? selectedProducts =
Get.arguments != null && Get.arguments is List<String?>
? Get.arguments as List<String?>
: [];
Future<void> scan() async {
try {
var result = await BarcodeScanner.scan();
final scanResult = result.rawContent;
DocumentSnapshot documentSnapshot =
await dataCollection.doc(result.rawContent.toString()).get();
if (documentSnapshot.exists) {
String itemName = documentSnapshot['name'] as String;
selectedItems.add(itemName);
Get.to(const StockIn(), arguments: selectedItems);
} else {
Get.snackbar('Error', 'Product not available');
}
} catch (e) {
Get.snackbar('Error', 'Failed to fetch data from Firestore: $e');
}
}
Kindly help if anyone know about that issue.