0

I want to show displayName of authenticated users from firebase in comments. I am storing displayName in firestore and updating every time user changed displayname.

eg: At initial user's displayname is Raj, i store it in firestore. user with displayname raj wrotes 5 comments and i show displayname from firestore. what is user change displayname to raj kumar and writes another 5 comments?? here i am stuck, i want to update somewhere such that i get realtime (latest) displayname of user for both past and present comments.. Any Ideas??

1 Answers1

0

You can use a StreamBuilder widget to listen to change from Firestore. It will automatically updates the name of your user

return StreamBuilder(
    stream: Firestore.instance
        .collection('user')
        .document(userId)
        .snapshots(),
    builder: (context, snapshot) {
      if (!snapshot.hasData) {
        return CircularProgressIndicator();
      }
      var userData = snapshot.data;
      return Center(
        child: Text("Username : ${userData['username']}"),
      );
    },
  );
Jérémy
  • 61
  • 1
  • 8