Disclaimer
This is Part 3 and the final part of a series of articles that explore and seek to provide newcomers with a high-level overview of what all the parts of a Flutter app consist of and do, so that they can hit the ground running.
While this series has been, to the best of my ability, unbiased in exploring the different components that make up a Flutter app, I think it wouldn’t be too bad to now share the solutions I use for my own projects.
As a warning though, these solutions seem intuitive and work for me, it is not only possible but also likely that they may not seem intuitive to you and as such may not work for you. With that being said, let’s begin.
State Management
I use MobX as my state management library of choice. It’s a slightly heavy-weight solution for smaller use-cases, but in my opinion it is in the middle, suitable for smaller cases and tested and powerful enough for handling the larger ones too. It also has code generation and minimal boilerplate, which are both really great bonuses for me.
Furthermore, it was also the first state-management solution whose theory and working principles really clicked with me, which is also one of the primary reasons for my bias towards it.
Dependency Injection
I use a combination of Provider and Get It for my dependency injection, Provider to aid in the injection of MobX Stores wherever they are required, and Get It for the injection of my service classes wherever those are required.
Although I do believe either one could handle both, I am biased towards Get It, for the Build-context-less functionality it provides, but also reluctant to leave Provider behind due to it being the “de-facto” way Stores are injected into Widgets and such, as mentioned in the MobX docs for Flutter.
And so I compromise, using Provider for Stores and Get It for everything else.
Local Data Persistence
My go-to choice for local data persistence is Hive, and for when I need a way to store more complex, relational data, Moor.
These libraries are the best fit for my use-cases, Hive fulfilling the need of fast key-value storage of important things such as user preferences and other, smaller bits of data that are used in places where it would heavily affect the user experience if users had to wait, and Moor fulfilling the need of a tabular, medium-sized database that can store relational data and also supports querying that data by criteria.
Network and Connectivity
Full disclosure, I haven’t required using the internet or an API in any of my apps yet, but my next app will have an API and a cloud database at it’s heart, and, the research I’ve done into which library I should use has largely lead me to consider Chopper for my use, due to the code generation it provides.
Architecture Pattern
The architecture I’ve used for the three apps I have in various stages of development ( as of the time of writing this ) is MVVM, due to the easier way I personally think each of it’s components translate to Flutter.
However, I also think that it’s components could translate to Flutter better, especially if I’m using MobX as the state management library of choice. As such, I’ve spent a bit of time developing a custom architecture solution for this, one that I intend to publish as a package on pub.dev after it’s stable and fulfills all of the basic requirements of an architectural pattern.
The architecture will be a combination of MVVM and the WSS triad mentioned in the MobX docs , and will provide a way to bind your MobX Stores to your UI more easily and in a more easily scalable and cleaner way.
Psst, It’s Tanzil from the future, here to let you know that the package I mentioned is live now on pub.dev, and you can find it <em>here</em>
The End
And with that, we reach the end of the third and final post in this series. In this post, I shared with you the packages I use for my own Flutter projects, along with the reasons behind my decision and my thoughts on each.
The post ends now, and so does this adventure, but like any good adventure, and any good story, it sets up the scene for the next great adventure, soon to begin, in each of our stories.
This is Tanzil Zubair, wishing you all the very best in your future endeavors. I thank you for reading this far, and sincerely hope you enjoyed this journey, and most importantly, learnt something new!