Scalable Flutter Folder Structure for Big Apps

Photo by Med Badr Chemmaoui on Unsplash

When starting a new project you need to plan the long run in order to finish the project cleanly.

I am a professional Flutter developer with 3 years of experience. I am going to show you how I design folder structure for my Flutter apps.

First we start with two folders called “global” and “modules”

We will add functions and widgets that will help our app globally in the global folder.

The global folder will contain these folders

  • Common will contain commonly used widgets like loading indicators, dialogs, and any widget you use frequently on your modules.
  • Widgets fill contain high-level widget files like your wrapped function of https://pub.dev/packages/flutter_form_builder fields or a datatable widget for example.
  • Utils will contain const variables you have created. These can be styles, design values. It can also contain functions you frequently use.
  • Themes will contain your themes created with official documentation: https://docs.flutter.dev/cookbook/design/themes
  • Controllers will contain controllers that you use globally in your modules or before starting the app.
  • Interceptors will contain for example a fetching interceptor or a route interceptor. I use Dio for data fetching so I create Dio’s interceptor there.
  • Endpoints will contain string URL functions that you use for data fetching. Using endpoints like this will make it quicker to update and see what endpoints you are using overall.
  • Models will contain JSON models you have created with official documentation here: https://docs.flutter.dev/development/data-and-backend/json
  • Services will contain functions that fetch from API.
  • Both services and models must be in global folder in a big app. The reason for this is you can use a service both in profile module and home module etc..
  • If you create models and services per module it will get complicated in the long run.

This way you can create an entire global folder suited for your app’s interests.

In the modules folder, we will have modules which have a view file, controllers, and widgets folder in order to separate big chunks of flutter code.

We will create modules based on pages. Here we have home and profile modules for example.

  • Controllers will contain controls (or view models. I am using GetX that is why I named them “Controllers”) you have created. It can be a GetX controller or other state management packages you have used.
  • Widgets folder will contain widgets that we will use on our view. I always give advice to cut chunks of your view into smaller widgets whenever possible.
  • And then there is your view. Which will be your view.. amazing isn’t it ? It should not be more than 300 lines of code max.
  • Business logic should be handled in your controllers. Widgets in your view should be separated by files then recalled on your view.

With this structure you can scale a big Flutter app easily.

Level Up Coding

Thanks for being a part of our community! More content in the Level Up Coding publication.
Follow: Twitter, LinkedIn, Newsletter
Level Up is transforming tech recruiting ➡️ Join our talent collective


Scalable Flutter Folder Structure for Big Apps was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Umut Arpat

Photo by Med Badr Chemmaoui on Unsplash

When starting a new project you need to plan the long run in order to finish the project cleanly.

I am a professional Flutter developer with 3 years of experience. I am going to show you how I design folder structure for my Flutter apps.

First we start with two folders called “global” and “modules”

We will add functions and widgets that will help our app globally in the global folder.

The global folder will contain these folders

  • Common will contain commonly used widgets like loading indicators, dialogs, and any widget you use frequently on your modules.
  • Widgets fill contain high-level widget files like your wrapped function of https://pub.dev/packages/flutter_form_builder fields or a datatable widget for example.
  • Utils will contain const variables you have created. These can be styles, design values. It can also contain functions you frequently use.
  • Themes will contain your themes created with official documentation: https://docs.flutter.dev/cookbook/design/themes
  • Controllers will contain controllers that you use globally in your modules or before starting the app.
  • Interceptors will contain for example a fetching interceptor or a route interceptor. I use Dio for data fetching so I create Dio’s interceptor there.
  • Endpoints will contain string URL functions that you use for data fetching. Using endpoints like this will make it quicker to update and see what endpoints you are using overall.
  • Models will contain JSON models you have created with official documentation here: https://docs.flutter.dev/development/data-and-backend/json
  • Services will contain functions that fetch from API.
  • Both services and models must be in global folder in a big app. The reason for this is you can use a service both in profile module and home module etc..
  • If you create models and services per module it will get complicated in the long run.

This way you can create an entire global folder suited for your app's interests.

In the modules folder, we will have modules which have a view file, controllers, and widgets folder in order to separate big chunks of flutter code.

We will create modules based on pages. Here we have home and profile modules for example.

  • Controllers will contain controls (or view models. I am using GetX that is why I named them “Controllers”) you have created. It can be a GetX controller or other state management packages you have used.
  • Widgets folder will contain widgets that we will use on our view. I always give advice to cut chunks of your view into smaller widgets whenever possible.
  • And then there is your view. Which will be your view.. amazing isn’t it ? It should not be more than 300 lines of code max.
  • Business logic should be handled in your controllers. Widgets in your view should be separated by files then recalled on your view.

With this structure you can scale a big Flutter app easily.

Level Up Coding

Thanks for being a part of our community! More content in the Level Up Coding publication.
Follow: Twitter, LinkedIn, Newsletter
Level Up is transforming tech recruiting ➡️ Join our talent collective


Scalable Flutter Folder Structure for Big Apps was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Umut Arpat


Print Share Comment Cite Upload Translate Updates
APA

Umut Arpat | Sciencx (2022-06-27T11:10:05+00:00) Scalable Flutter Folder Structure for Big Apps. Retrieved from https://www.scien.cx/2022/06/27/scalable-flutter-folder-structure-for-big-apps/

MLA
" » Scalable Flutter Folder Structure for Big Apps." Umut Arpat | Sciencx - Monday June 27, 2022, https://www.scien.cx/2022/06/27/scalable-flutter-folder-structure-for-big-apps/
HARVARD
Umut Arpat | Sciencx Monday June 27, 2022 » Scalable Flutter Folder Structure for Big Apps., viewed ,<https://www.scien.cx/2022/06/27/scalable-flutter-folder-structure-for-big-apps/>
VANCOUVER
Umut Arpat | Sciencx - » Scalable Flutter Folder Structure for Big Apps. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/06/27/scalable-flutter-folder-structure-for-big-apps/
CHICAGO
" » Scalable Flutter Folder Structure for Big Apps." Umut Arpat | Sciencx - Accessed . https://www.scien.cx/2022/06/27/scalable-flutter-folder-structure-for-big-apps/
IEEE
" » Scalable Flutter Folder Structure for Big Apps." Umut Arpat | Sciencx [Online]. Available: https://www.scien.cx/2022/06/27/scalable-flutter-folder-structure-for-big-apps/. [Accessed: ]
rf:citation
» Scalable Flutter Folder Structure for Big Apps | Umut Arpat | Sciencx | https://www.scien.cx/2022/06/27/scalable-flutter-folder-structure-for-big-apps/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.