How to properly structure flutter project with API & Local data storage?

7,012

There is no right or wrong on how to structure your Flutter project. You can put everything in a single file. Also it depends on the package its being used, for example I use BLoC as state management and these are some project structures that the package recommends:

I don't use any of those, I made my own project structure that I will explain in a moment. There's a package layout convention for Dart (not for Flutter projects).

I use the following structure:

├──lib/
│  ├──blocs/
│  ├──models/ 
│  ├──repositories/
│  ├──screens/
│  ├──utils/
│  ├──widgets/
│  └──main.dart

I separate everything in folders so front-end devs can work on the widgets folder where there is all the design stuff and back-end devs can works on the blocs folder where there is all the logic.

Remember there is no wrong or right answer. Check-out your recommended project structure that your favorite state management package recommends or watch this talk: Keep it Simple, State: Architecture for Flutter Apps (DartConf 2018)

Share:
7,012
Ashok
Author by

Ashok

I am a student who is very fond of learning

Updated on December 01, 2022

Comments

  • Ashok
    Ashok over 1 year

    So i have created some apps in flutter with laravel backend, which works online only. Now i need to make an app work offline as well for which i am thinking of using Hive. But now the problem is i cannot find a good resource on how to properly manage such large project. My past projects were mostly small, but with local storage and all, i want to use interfaces & repositories to manage the project. But i can't figure out how to put everything together so the code is manageable.

    So can someone help me here? Is there any such project that i can study, or perhaps even an article or a video. Anything that sheds light on how to structure large projects in flutter will be appreciated.