【发布时间】:2018-07-17 00:09:15
【问题描述】:
我有一个查询来查找指定条形码的 documentID,如下所示:
Future findBarcode() async {
String searchBarcode = await BarcodeScanner.scan();
Firestore.instance.collection('${newUser.userLocation}').where('barcode', isEqualTo: '${searchBarcode}').snapshots().listen(
(data) {
String idOfBarcodeValue = data.documents[0].documentID;
print(idOfBarcodeValue);
}
);
}
但是,我想在函数之外引用 idOfBarcodeValue。我正在尝试找到一种方法将其传递给另一个函数以传递给 SimpleDialog。
目前,函数之外的任何东西都无法识别它。它确实有效,打印验证。
下面是正在执行的扫描功能:
Future scan() async {
try {
String barcode = await BarcodeScanner.scan();
setState(() => this.barcode = barcode);
} on PlatformException catch (e) {
if (e.code == BarcodeScanner.CameraAccessDenied) {
setState(() {
this.barcode = 'The user did not grant the camera permission!';
});
} else {
setState(() => this.barcode = 'Unknown error: $e');
}
} on FormatException{
setState(() => this.barcode = 'null (User returned using the "back"-button before scanning anything. Result)');
} catch (e) {
setState(() => this.barcode = 'Unknown error: $e');
}
}
【问题讨论】:
标签: search dart google-cloud-firestore flutter