【发布时间】:2022-01-01 23:55:38
【问题描述】:
我有一个按钮可以让用户删除他们的帐户。当用户注册他们的电子邮件并将姓名保存到名为 users 的 Firestore 集合中时,我想在集合的文档中搜索 uid 字段等于当前用户 uid 的位置,然后删除该文档。删除帐户有效,但文件无效,我没有收到任何错误,我不确定我做错了什么...
CollectionReference users = FirebaseFirestore.instance.collection('users');
TextButton(
onPressed: () async {
try {
await users
.where('uid', isEqualTo: _auth.currentUser!.uid).firestore.doc(users.doc().path).delete();
await _auth.currentUser!.delete().then((value) =>
Navigator.pushReplacement(context, MaterialPageRoute(
builder: (context) => const WelcomeScreen())));
} on FirebaseAuthException catch (error) {
Fluttertoast.showToast( msg: error.message.toString(),
gravity: ToastGravity.TOP,
backgroundColor: Colors.red,
textColor: Colors.white);
} on FirebaseException catch (error) { Fluttertoast.showToast(
msg: error.message.toString(),
gravity: ToastGravity.TOP,
backgroundColor: Colors.red,
textColor: Colors.white);
}
},
child: const Text( 'Delete', style: TextStyle(color: Colors.red),
))
【问题讨论】:
-
请告知您遇到的错误可能有助于更多地了解您的问题
-
由于某种原因,我在调试终端中没有收到错误
-
试试我的答案,如果它不起作用,请告诉我
标签: firebase flutter dart google-cloud-firestore firebase-authentication