Flutterfire 如何获取唯一 ID doc() 中的数据?

Flutterfire how can i fetch data inside of unique id doc()?

我试图在我的 flutter 应用程序中获取一个 string/check 用于验证的字符串。我一直在尝试使用 .where() 函数,但是当我这样做时他们给了我这个错误

The argument type 'Future<QuerySnapshot<Object?>>' can't be assigned to the parameter type 'Future<DocumentSnapshot<Object?>>?'

这是给我错误的代码


 final phoneNumber = ModalRoute.of(context)!.settings.arguments as String;
 CollectionReference users = FirebaseFirestore.instance.collection('users');

 return FutureBuilder<DocumentSnapshot>(
      future: users.where("phoneNumber", isEqualTo : phoneNumber).get(),
      builder:
          (BuildContext context, AsyncSnapshot<DocumentSnapshot> snapshot) {
        if (snapshot.hasError) {
          return const Text("Something went wrong");
        }
        if (snapshot == null || !snapshot.data!.exists) {
          return const Text("data doesn't exist");
        }

        if (snapshot.hasData) {
          return const Text("data exist already");
        }

        if (snapshot.connectionState == ConnectionState.done) {
          Map<String, dynamic> data =
              snapshot.data!.data() as Map<String, dynamic>;
          return Text("Full Name: ${data['full_name']} ${data['last_name']}");
        }

        return const Text("loading");
      },
    );

我已经尝试并搜索了 3-4 个小时,但所有参考资料都告诉我我需要输入唯一 ID

看起来像这样

 final docSnapshot = await Firestore.instance
    .collection("$Friseur/1/$Tag/1/$Uhrzeit")
    .document(${doc_id_here})
    .get();

    if(docSnapshot.exists) {
      setState(...)
    }
    else {
      setState(...)
    }

在 where 函数之后添加 doc 函数,文档 id 因为 future 参数接受 Future>?

future: users.where("phoneNumber", isEqualTo : phoneNumber).doc(documentId).get(),

改变FutureBuilder<DocumentSnapshot> to FutureBuilder<QuerySnapshot> 当你使用 where 操作时 return QuerySnapshot.