如何获取 QR 码的字符串值并将其存储到 firebase 以便它链接到特定用户

How to get the string value of QR code and store it into firebase so it links to specific user

我正在尝试通过 QR 扫描制作忠诚度应用程序,但不确定如何获取为每个用户生成的 QR 码的字符串值,然后将其存储在 firebase 中,以便 links然后,特定用户更新用户二维码在子集合中被扫描的次数 linked 到用户集合。

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,它为每个用户生成二维码,但我不确定如何将数据值 link 到 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');
    }
  }

这是我的扫描功能,它在不同的页面上。

用户合集 https://gyazo.com/803b3ba624a431774ec59f45c1566185

积分收集 https://gyazo.com/3d284e344883e85783bedb23a7cff9cc

试试这个

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');
    }
  }