By following these steps, you will now add the barcode reading feature to the existing app:
- In the ml.dart file, add a new async method, called readBarCode, that takes File as a parameter, and returns a string:
Future<String> readBarcode(File image) async {}
- At the top of the readBarCode method, declare a String, a FirebaseVision, a FirebaseVisionImage, and a BarcodeDetector, as shown:
String result = '';
final FirebaseVision vision = FirebaseVision.instance;
final FirebaseVisionImage visionImage = FirebaseVisionImage.fromFile(image);
BarcodeDetector detector = vision.barcodeDetector();
- After the declarations, use a try/catch. In the try block, call the BarcodeDetector detectInImage method to retrieve a list of Barcode objects. Then, for each barcode in the list, add its display value to the result string. In the catch block, just print the error that was returned:
try {
List<Barcode> results...