- Flutter Riverpod App Template
- Architecture structure
- Folder structure
- Architecture flow example
- How to use
This project has everything you need to start a Flutter project with Riverpod as the state management tool.
This template is built with architecture that consists of four main layers: Presentation (UI), Service, Domain (Models, DTOs) and Data (Repositories).
This layer contains only UI elements (widgets) and controllers that handle events and update interface.
- Present user interface, render widgets, play animations
- Minor validation logic, text input listeners
- Hold some business logic
- Manage widget state
- Interact with the Data layer (repositories)
This layer contains data models and represents them as immutable data classes in Dart, along with any business logic we may need to modify them.
Data layer combines different repositories and handles business logic.
The Repositories are very handy if your app has a complex data layer with many different endpoints that return unstructured data (such as JSON) that you want to isolate from the rest of the app.
- Isolate domain models from the implementation details of the data sources in the data layer
- Convert data transfer objects to validated entities that are understood by the domain layer
Services act as a middle-man between the controllers (widget-only) and the repositories (data-only). They are not concerned about parsing data or updating the widget state.
- This service communicates with remote sources (REST API, sockets, etc.)
- This service communicates with Cloud Firestore.
- This service communicates with Firebase Authentication.
- This service communicates with device's location (via GPS and/or Google Services)
- This service communicates with device's storage to provide data caching.
- This service communicates with device's hardware and software, providing information about them.
Top-level folder structure that can be found under /lib:
- constants contains app constants (e.g. endpoint names)
- features contains all application's UI elements (screens, widgets) and corresponding controllers
- models contains data model classes
- providers contains all global providers (mainly for services and repositories)
- repositories contains all repositories
- router contains application's router powered by go_router
- services contains all services
- shared contains widgets and other elements that are shared across different parts of the app
- theme contains custom theme data
- utils contains utilities that do not belong in the shared or features folders
- main.dart core file that initializes our application
Installation is easy and can be done in seconds! Clone this project, make sure you're on the latest Flutter version, open the newly cloned project and run the following commands:
Download all dependencies:
flutter pub get
Run the app:
flutter run