首页 > 解决方案 > 当在文本字段中输入字段中的数据时,Flutter Firestore 显示文档 ID

问题描述

这是我的 Firestore 数据库 的屏幕截图截屏 文档 ID 以用户 uid 命名。

下面是我到目前为止的代码

  Widget _inputEmail() {
return StreamBuilder<QuerySnapshot<Map<String, dynamic>>>(
    stream: FirebaseFirestore.instance
        .collection("users")
        .snapshots(),
    builder: (context, snapshot) {
    return Container(
      width: 355,
      padding: EdgeInsets.only(bottom: 20),
      child: TextFormField(
        controller: _email,
        decoration: InputDecoration(
            hintText: 'Email',
            helperText: 'Enter Email',
            suffixIcon: IconButton(
              icon: Icon(Icons.navigate_next),
              onPressed: () {
                FirebaseFirestore.instance
                    .collection('users')
                    .where('email', isEqualTo: _email)
                    .get()
                    .then((snapshot) => print(snapshot.docs[0].data()['user.uid']));
              },
            ),
            border: UnderlineInputBorder()),
      ),
    );
  }
);

我想要实现的是,当用户输入电子邮件时,在此文本字段中,它将显示该电子邮件所在位置的文档 ID,以便我可以创建另一个功能来修改货币数据。

应用截图

应用截图

基本上这将是一个转账菜单,其中输入的电子邮件是收件人的电子邮件,按下按钮后,用户可以输入他们想要转账到目标电子邮件的金额。然后,当前用户的金额将转入收款人的账户。

抱歉问得太多了,我还在学习 Firestore 如何为 uni 项目工作。

标签: fluttergoogle-cloud-firestore

解决方案


获取文档 ID 使用snapshot.docs[0].id


推荐阅读