flutter - 当在文本字段中输入字段中的数据时,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 项目工作。
解决方案
获取文档 ID 使用snapshot.docs[0].id
推荐阅读
- sql-server - 带括号的环绕查询导致 XML 错误
- audio - linux:使用 gstreamer 的虚拟麦克风
- java - 测试中没有 EntityManager 的持久性提供程序
- email - 将文件附加到电子邮件而不将内容保存到本地文件
- csv - 用于映射两个 csv 文件中的列的脚本
- amazon-web-services - 如何在不使用主键的情况下执行 getitem 或查询以检索 DynamoDB 中的最后更新记录
- javascript - 如何分组一堆
的 - vba - 解析未完全加载 VBA 的网站
- r - 如何根据另一个矩阵的真/假索引替换矩阵中的值?
- java - 使用 CXF 生成 SOAP 1.2 端点的 Java Spring Boot