【问题标题】:I want to get user id in a get function我想在 get 函数中获取用户 ID
【发布时间】:2020-12-22 20:00:02
【问题描述】:
 Future<String> getCurrentUser() async {
    final FirebaseUser user = await _auth.currentUser();
    final uid = user.uid;
    return uid;
  } 

我想在文档中添加用户 uid,但无法获取。

 Stream<List<RezervasyonListesi>> get rezervasonlarlistesi1 {
   return rezervasyonCollectionRef
       .document() // **In document I want refer to user uid ;**
       .collection("rezerve")
       .snapshots()
       .map(_rezervasyonlistesifromsnap);
 }

我试过了,但没用


  Stream<List<RezervasyonListesi>> get rezervasonlarlistesi {
    getCurrentUser().then((value) {
      return rezervasyonCollectionRef
          .document(value)
          .collection("rezerve")
          .snapshots()
          .map(_rezervasyonlistesifromsnap);
    });
    
  }

Stream> 不是未来的类型,因为我不能在该函数中使用异步。没有 ascyn 如何获得我的 firebase 用户 uid。

RezervasyonListesi 类


class RezervasyonListesi {
  final String name;
  final String address;
  final String image;
  final String rating;
  final String description;
  RezervasyonListesi(
      {this.address, this.description, this.image, this.name, this.rating});
}

【问题讨论】:

    标签: firebase flutter dart google-cloud-firestore


    【解决方案1】:

    试试这个。

    Stream<List<RezervasyonListesi>> get rezervasonlarlistesi async*{
     String currentUser = await getCurrentUser();
     yield* rezervasyonCollectionRef.document(currentUser.uid).snapshots().map((snapshot){
        return snapshot.data;
     });
    }
    

    【讨论】:

    • 没有为类型 'DocumentSnapshot' 定义 getter 'snapshot'。尝试导入定义“快照”的库,将名称更正为现有 getter 的名称,或者定义一个名为“快照”的 getter 或字段。dartundefined_getter
    • 这次是说 :))) 没有为类型“DocumentSnapshot”定义 getter 'value'。尝试导入定义“value”的库,将名称更正为现有 getter 的名称,或定义名为“value”的 getter 或字段。dartundefined_getter
    • 试试.data.data()
    • withoud () - >返回类型 'Map' 不是一个 'List',正如闭包的 context.dartreturn_of_invalid_type_from_closure 所要求的那样
    • with data() -> 表达式不计算为函数,因此无法调用
    猜你喜欢
    • 2012-10-27
    • 2020-10-15
    • 2021-03-12
    • 2019-11-25
    • 2020-08-03
    • 2017-12-22
    • 2020-01-30
    • 2021-12-15
    • 2022-01-11
    相关资源
    最近更新 更多