5 Tips To Know Before You Start Developing Your App with Flutter

Gaspard Merten
Flutter Community
Published in
3 min readMar 18, 2020

--

Photo by Sam Dan Truong on Unsplash

1. Always cancel your stream subscription:

When I started learning Flutter, I did not always think about canceling my stream subscription because that was something I never heard about.

But what I learned is that even if your widget is no longer alive, well, your stream subscription still is! And that can become a major issue when the widget is re-created a certain number of times, leading to possible process overload!

To prevent that, you could just add a conditional block that checks if the widget is mounted, but that would still result in a useless loss of performance.

So to prevent that here is how you should manage your stream subscription in Flutter:

But the easiest way can sometimes be to just use a StreamBuilder. It is a very powerful widget that will manage the state of its child depending on the stream provided! If you want to know more I would suggest that you read this article from Manzurur Rahman Khan.

--

--

Gaspard Merten
Flutter Community

Co-Founder & CTO @ GiveActions 🛠️ | Writer on Medium 🪶 | Flutter & Django ❤️ | Polytechnic School of Brussels 🎓| Mountain Lover 🗻