简体   繁体   中英

Firebase/ Flutter: Get Current User inside get function

Is there a way to get the current user from Firebase

final FirebaseUser user = await _auth.currentUser();

inside get function like so:

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

This should do the job:

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

To finally get the user the following lines in an async function:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM