This project shows how to implement a simple architecture using Riverpod.
The architecture consists of the following components:
The repository layer is responsible for obtaining data from a specified source. We use abstraction here to be able to switch the source easily if necessary.
The TodoRepository defines the interface of the repository, FakeTodoRepository is a simple implementation storing data in-memory.
The model defines the data that should be displayed in the application.
The TodoListState contains the different states the todo list can have (loading, error, data).
The TodoListController holds this state and is responsible for making changes to the state.
Contains the UI elements of the application. It watches the state of the TodoListController and rebuilds when the state changes.
- Make a
TodoRepositoryavailable via aProvider. - Implement a
TodoListStateusing the following states: loading, error, data - Implement the
TodoListController(extendsStateNotifier) to load the data. Make it available via aStateNotiferProvider. - Watch state of
TodoListControllerin theTodoListPage. Handle loading, error, and data states. - Implement pull to refresh
- Implement insertion of a new todo
- Implement deletion of a todo
In this project following packages have been added:
Used for state management
Used when generating models using freezed. Allows to convert the models to JSON.
Needed by the freezed package to annotate freezed classes.
Adds useful utility functions when working with collections
Handles code generation
Generates utility functions for models
Allows serialization and deserializations for models to/from JSON.
We use the freezed package to generate files. Use following command to run build_runner.
fvm dart run build_runner watch --delete-conflicting-outputs # with fvm
dart run build_runner watch --delete-conflicting-outputs # without fvm