If you’re building a big and complex app, it’s important to consider the folder structure. Without it, your unorganized code can hinder your progress over time.
Each state management library in Flutter has many folder structure patterns, including Riverpod. However, the pattern We are sharing with you is easy to understand, test, debug, and scale. It also allows for easy code clean-up and refactoring, as well as simple migration from any other structure. Let’s take a closer look and see how simple it actually is.
First, divide the app into features. Say your app has four features; your structure will look like this:
The app-level structure includes three layers:
- Presentation Layer
- Logic Layer
- Data Layer
But for better organization, modify the structure for each feature:
- Presentations :- This folder contains the widget code that’s rendered on the screen.
- States :- This folder contains all the states that widget apdat to render something different.
- Notifiers :- This folder contains the business logic to manage the widget state.
- Services :- This folder contains the business logic to manage the application state.
- Models :- This folder contains the data model to share data coming from the repository to notifiers or services.
- Repositories :- This folder contains the handling for data coming in and out from your database or server.
- Data Providers :- This folder contains all your data sources, such as fake data, server calls, or database calls.
That’s it! You can add as many features as you want and remove them easily if they’re not required. Test each layer individually, debug only the folder with the problem, and solve it quickly like this:
You can also explore example here. We hope to see you in our coming articles.