I have a flutter app with drawer navigation. When open, the drawer is overlapping a widget (let’s call it Screen_1).
I would like to force the Screen_1 rebuild when the user dismisses the drawer. What is the best way to do it? Thanks.
EDIT. A specific example: In the drawer the user can change their picture. But when they dismiss the drawer (eg by clicking outside of it), Screen_1 still shows their old picture. I’d like Screen_1 to show the new picture.
2
Answers
I have a few suggestions that might help you and you can choose based on your need and u can look into these:
ValueNotifier : https://api.flutter.dev/flutter/foundation/ValueNotifier-class.html
If you are pressing a button to close it you can use:
Navigator.pushReplacement
Or lastly
callback function
example:
First this is my user/authentication class and i user change ChangeNotifier so i can notify widget when needed to rebuild with the new data also i use setProfilePicture() to update the data and call notifyListeners():
so if i want a widget to be rebuild i will do this by using Consumer:
dont forget that you need to add the provider in main like this: