firebase - 如何获取 QR 码的字符串值并将其存储到 firebase 以便链接到特定用户
问题描述
我正在尝试通过 QR 扫描制作忠诚度应用程序,但不确定如何获取生成给每个用户的 QR 码的字符串值,然后将其存储在 firebase 中,以便它链接到特定用户,然后更新次数用户的二维码已在链接到用户收藏的子收藏中被扫描。
QrImage(
data: '${user?.uid}',
version: QrVersions.auto,
size: 300,
errorStateBuilder: (cxt, err) {
return Container(
child: Center(
child: Text('Error',
textAlign: TextAlign.center,
style: new TextStyle(color: Colors.red),
),
),
);
},
),
这是我的 QRImage,它为每个用户生成 QR 码,但我不确定如何将数据值链接到 firestore 集合。
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');
}
}
这是我在不同页面上的扫描功能。
解决方案
尝试这个
Future scan() async {
try {
String barcode = await BarcodeScanner.scan();
setState(() => this.barcode = barcode);
print("scanned sucsessfully");
//plus one to points when scanned
String userId = (await FirebaseAuth.instance.currentUser()).uid;
final CollectionReference pointsCollection = Firestore.instance.collection("users");
await pointsCollection.document(userId).collection('points').document(userId)
.updateData({
"points": FieldValue.increment(1),
"transactions": FieldValue.increment(-1)
});
} 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');
}
}
推荐阅读
- yammer - SharePoint 2010 CEWP 中的嵌入式 Yammer 脚本使用不同的 Yammer 源打开多个新窗口
- javascript - ES6 命名导出和默认导出之间的可变差异
- java - 我对这段 Java 代码有一些问题,并且出现错误
- r - R rtweet search_30day 消息:超出速率限制
- java - 如何修复“javax.net.ssl.SSLHandshakeException:TLS 服务器证书在 2019 年 4 月 16 日之后颁发并由不受信任的旧版赛门铁克根 CA 锚定”
- c++ - 具有扩展方法的自定义类
- python - Pycharm 缩进样式,如 vs 代码中的彩虹缩进扩展
- java - 自定义注释处理器未定位带注释的类
- go - 如何在 KrakenD 中使用带有 TLS 的客户端?
- python - 执行 20 多个 SQL 文件的最有效方法?