Search code examples
flutterdart

How to organize dart files inside packages in flutter


I'm new at programming using flutter and I'd like to develop a small project containing a few screens: Login, Home, Settings, User, PurchaseHistory, etc.

I need to organize the code inside packages so that it can readable easily.

If I develop an Android App, I'd create some packages: model, activity, fragment, util, etc. If I create a LoginActivty, I'd put it inside activity package. If I create a User model, I'd put it inside model package. And so on.

So If I develop a flutter project, where am I supposed to put all of the files I create so far?

For now I've created only model package.


Solution

  • First of all, in Flutter we don't deal with activities or fragments directly, that is a naming convention from Android itself.

    There are many options to architect your app and organize your folders. I wouldn't say that there is a holy grail solution. So you have to try some of them and see the best fit for you.

    At the end of this article, I show an option to a folder structure when working with flavors, like this:

    Flavoring

    But there are plenty of others, so I recommend you to see how some of the GitHub projects are organized, a good way to start is having a look at the projects from this repository. Especially the 'Open Source Apps' section.