Flutter:从扫描的条形码编号中获取信息

Flutter: Get information from scanned barcode number

我刚接触Flutter,目前正在开发一个需要读取条码的应用。所以我使用了 barcode_scan 库,现在我可以从扫描的条形码中获取条形码编号。

明确地说,我不是在问如何扫描条形码/获取条形码编号。

我的问题是:如何从 Flutter 中的条形码编号(例如产品名称)中获取有关产品的更多信息?我可以从 barcode_scan 库中执行此操作,还是需要其他东西?

编辑: 忘了说了,扫描二维码的时候我能得到它编码的信息(比如产品名称或者URL),但是这个不是带条形码的情况。

我目前的(相关)代码如下:

String result = 'Hey there!';

Future scanBarcode() async {
    if(await Permissions.checkCameraPermission()) {
        try {
            await BarcodeScanner.scan().then((scan_result) {
            //here scan_result is the obtained barcode number
            setState(() { result = scan_result; });
        });

        }
        //handling exceptions...
    }
    else {
        setState(() { result = 'Camera permission denied'; });
    }
}

(旁注,这里 Permissions.checkCameraPermission() 是我创建的一个函数,用于检查是否授予相机权限,不应该与问题相关)。

我正在使用相同的插件为我的 flutter 应用程序扫描条形码或二维码..

String result = 'Hey there!';

Future scanBarcode() async {
    if(await Permissions.checkCameraPermission()) {
        try {
            // I get the scan result from BarcodeScanner this way and it is working for me.
            result = await BarcodeScanner.scan();
        }
        //handling exceptions...
    }
    else {
        setState(() { result = 'Camera permission denied'; });
    }
}

好吧,似乎从 Flutter 中唯一可行的方法是使用条形码查找 API,就像评论中提出的 @RichardHeap 一样。如果我的应用程序只有 Flutter(没有连接后端服务器),我相信我会那样做。

不过我想我还是把条形码本身发送到后端,然后在服务器端处理吧。

我的理解是,在扫描代码时,您需要有关产品的信息/数据。

如果我没理解错的话,条形码有好几个聚合器。您可以从他们那里获取 API。但是没有一个地方可以获取所有信息。