Flutter StreamBuilder best practice
Improve performance like a pro
StreamBuilder is one of the most crucial widgets to prevent using setState
(Which rebuilds all your widget) and rebuild only the changed widget. Using it reduce the number of widgets that should rebuild on updating UI which causes to increase the performance of the app in term of building UI. You should already see practices on how to use StreamBuilder in Flutter but I am going to show a best practice of how to use a StreamBuilder to have a minimum rebuild on our widgets and increase performance.
I will create this simple app:
I will tap on the Increase age button (Which increases the user age by one) 5 times then 3 times on Add A to name button (Which adds an “A” at the end of the user name). After each button press our UI should rebuild to show new user data. I will use Android Studio Widget rebuild state to measure the number rebuild for each widget, then I will add this number to a screenshot from devTools of app UI to find a best practice with minimum widget rebuild during this action.