如何获取Firestore文档特定数据Flutter

时间:2020-05-14 10:21:01

标签: firebase flutter dart google-cloud-firestore

My FIrestore data collections

当我按下按钮时,我想为我的“文本”小部件获取该电子邮件地址。

2 个答案:

答案 0 :(得分:1)

您可以尝试以下操作:

void _onPressed() {
  Firestore.instance.collection("users").getDocuments().then((querySnapshot) {
    querySnapshot.documents.forEach((result) {
      print(result.data["email"]);
    });
  });
}

这将检索集合中的所有电子邮件。


如果您知道文档ID,则可以执行以下操作以检索一封特定于文档ID的电子邮件:

  void _onPressed() async{
    var firebaseUser = await FirebaseAuth.instance.currentUser();
    Firestore.instance.collection("users").document(firebaseUser.uid).get().then((value){
      print(value.data["email"]);
    });
  }

以上假设您将currentuserid作为文档ID。

答案 1 :(得分:-1)

如果您知道要查找的电子邮件地址,则可以使用 where 函数。

$ cat t1835.cu
#include <thrust/scan.h>
#include <thrust/execution_policy.h>

#include <iostream>

int main(){
  const int N = 10;

  //Yes, I wish to use raw pointers rather than nice device vectors.
  int* data;
  if(cudaMalloc(&data, N * sizeof(int))!=cudaSuccess){
    std::cout<<"Couldn't allocate!"<<std::endl;
    return -1;
  }
  cudaMemset(data, 0, N * sizeof(int));
  const int answer = thrust::transform_reduce(thrust::device,
    data, data + N,
    []__device__(auto &x) -> int32_t {
      //I would like to change the values of data here
      x = 3;
      return 2;
    },
    int32_t{0},
    []__device__(const int32_t running_sum, const int32_t this_value) -> int32_t {
      return running_sum + this_value;
    }
  );

  if(answer!=20){
    std::cout<<"Wrong answer!"<<std::endl;
    return -1;
  }
  int *h_data = new int[N];
  cudaMemcpy(h_data, data, N*sizeof(data[0]), cudaMemcpyDeviceToHost);
  cudaFree(data); //In actuality, I'd do something with transformed data here
  std::cout << h_data[0]  << std::endl;

  return 0;
}
$ nvcc -lineinfo -arch=sm_70 -O3  -o t1835 t1835.cu -std=c++14 --expt-extended-lambda
$ ./t1835
3
$