Firebase / Flutter:在获取功能内获取当前用户

时间:2020-06-24 21:01:25

标签: firebase flutter dart firebase-authentication

是否可以从Firebase获取当前用户

final FirebaseUser user = await _auth.currentUser();

内部获取函数如下:

class DatabaseService{
    Stream<List<AdModel>> get myAds {
    
        final CollectionReference userAdCollection = Firestore.instance.collection(uid);
        print(uid);
    
        return userAdCollection.snapshots()
            .map(_adListFromSnapshot);
    
      }
}

1 个答案:

答案 0 :(得分:0)

这应该可以完成工作:

class DatabaseService{
    Future<FirebaseUser> get user => _auth.currentUser();
}

要最终在异步功能中获得用户以下几行内容:

DatabaseService service = DatabaseService();
FirebaseUser user = await service.user;