Reputation:
I am building a forum-like mobile application with flutter. When uploading a post, i saved the user details such as username, profile picture and details of the post into firebase as fields for that post's document. (Username and profile picture of the person who posted will be shown on the post) However, when i change my profile picture or username afterwards in settings, those appearing on the post were not updated accordingly. How do i rectify this such that relevant changes to user information will apply to the posts?
This is a snippet of how i had saved the data. I understand why the corresponding data will not update but i am not sure how to go about restructuring the code.
Upvotes: 0
Views: 5284
Reputation: 1559
you can use a StreamController for this purpose. define a StreamController at application scope. you can subscribe to the stream at the widget where you are showing the profile picture and you can write to the stream when you update the profile picture from another widget, once you write to the stream, the subscribed widget will get the information and you can update the image using this information.
Upvotes: 1