如何获取二维码的字符串值并将其存储到firebase中,以便链接到特定用户
我正在尝试通过QR扫描制作忠诚度应用程序,不确定如何获取生成给每个用户的QR码的字符串值,然后将其存储在firebase中,以便它链接到特定用户,然后更新链接到用户集合的子集合中扫描用户QR码的次数如何获取二维码的字符串值并将其存储到firebase中,以便链接到特定用户,firebase,flutter,google-cloud-firestore,qr-code,Firebase,Flutter,Google Cloud Firestore,Qr Code,我正在尝试通过QR扫描制作忠诚度应用程序,不确定如何获取生成给每个用户的QR码的字符串值,然后将其存储在firebase中,以便它链接到特定用户,然后更新链接到用户集合的子集合中扫描用户QR码的次数 QrImage( data: '${user?.uid}', version: QrVersions.auto, size: 300,
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),
),
),
);
},
),
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');
}
}
这是我的QRImage,它为每个用户生成QR代码,但我不确定如何将数据值链接到firestore集合
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),
),
),
);
},
),
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');
}
}
试试这个
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');
}
}