How to properly structure flutter project with API & Local data storage? [closed]
Asked Answered
T

1

5

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.

Treehopper answered 5/9, 2020 at 5:58 Comment(0)
W
8

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)

Wraparound answered 28/9, 2020 at 20:43 Comment(4)
is it necessary if we add more cubits folder if we also want to use cubits?Charie
@AriefWijaya Yes you can, after the cubit release I create a state management folder and put all the files with this naming convention: file_cubit.dart or file_bloc.dartWraparound
Could you please explain what repositories should stand for?Inhibitor
@PhiliposD. Here are some links that may help: en.wikipedia.org/wiki/Software_repository bloclibrary.dev/#/architecture?id=repositoryWraparound

© 2022 - 2024 — McMap. All rights reserved.