Modular Flutter Apps — Design and Considerations

Gonçalo Palma
Flutter Community
Published in
9 min readNov 14, 2019

--

Photo by Blake Wheeler on Unsplash

When working in a big project in native Android Development, we may suffer a lot from long build times and an incoherent code structure. That’s why many projects tend to divide their codebase into multiple modules. This ensures not only that the project is divided into smaller units that can be independently changed but it also reduces build time since each module can be built separately and, if a module has not been changed, when building the app it won’t be rebuilt. Some apps report a decrease of the total build time from 1 minute and 10 seconds to 17 seconds.

In the Flutter verse, each time that we compile our code, all the dependencies are also compiled, so we might think that the compile times shouldn’t be affected, however, are there other benefits to do this? Is it worth it? Let’s explore it.

Dividing a project into different modules

Though we do not have the Gradle system that let us easily divide the project into different modules, we can take advantage of the pub package system. How? We can add a new dependency to our project by adding it to the pubspec.yaml file, where it is going to be downloaded from pub.dev. However, we can also use this system to retrieve a library that is currently hosted locally in our machine by referencing its path instead:

--

--

Gonçalo Palma
Flutter Community

Author, Flutter Lead Developer @Pvotal Tech. Organizer, Google Developer Expert for Flutter and Dart, Lead Flutter Developer. 🌍 https://gpalma.pt/