Folder organization in Flutter
Or “Where did I put that file…?”
When I started coding in flutter, I arranged my folders as in my first tutorial:
-model
-SomeModel.dart
-pages
-page1
-page1Controller.dart
-Page1Screen.dart
-page2
-services
-DataService.dart
-AnotherDataService.dart
-widgets
-Widget1.dart
I learned soon after that dart style is to have filenames in lower case with underscore, that is some_model.dart
instead of SomeModel.dart
. But that is easy to change.
The bigger problem is that when you have a slightly more complex app, this method is terrible. Each page is in a different folder, but some pages use the same widgets and models and some don’t. So to find the model used by page1
I need to go to the models
folder, and there look for... what? Are all the models in the top level? Do I put folders for page screens in there as well?
As the models are used by feature, it makes sense to split them into folders according to feature:
-models
-feature1
-model_1.dart
-model_2.dart
-feature2
-model_3.dart
However, now what? Do I add these subfolders in each of the main folders? This is absurd.