Flutter template project - A simple TODO list app
In addition to the Flutter's build modes (debug, profile, release), the project has 4 flavours/schemas for defining environments:
- mock - mock environment that uses mock values. Launches
main_mock.dart
- dev - development environment that targets a development server. Launches
main_dev.dart
- staging - staging environment that targets a staging server. Launches
main_staging.dart
- production - production environment that targets a production server. Launches
main_production.dart
To run the app use the following command:
flutter run --flavor dev -t lib/main_dev.dart
or edit run configurations in Android Studio:
- Go to EditConfigurations...
- Enter configuration name: DEV, STAGE, PROD
- Enter dart entry point: main_dev.dart, main_staging.dart, main_production.dart
- Enter additional run args: --flavor=dev, --flavor=staging, --flavor=production
- Enter build flavor: dev, staging, production
See flavor_config.dart for environment specific config.
For adding an additional Flutter flavours see the official documentation and this blog post.
This is the main entry point for accessing and manipulating tasks data. The rest of the app should not invoke tasks' endpoints directly or query cached data. All tasks operations should go through this service.
Implementations:
- TasksRemoteDataSource - Uses the ApiService to contact a remote server;
- TasksCacheDataSource - Uses in-memory cache to retrieve tasks;
- TasksRepository - Uses both TasksRemoteDataSource and TasksCacheDataSource to fetch cached data when available; Provides subscription for updates;
- TasksStubDataSource - Stub;
Abstraction over the API communication that defines (all) endpoints. This templates uses Chopper, an http client generator, to make network requests.
JSON models are serialized using a code generation library.
For one time code generation run this command in terminal: flutter pub run build_runner build
For subsequent code generations with conflicting outputs: flutter pub run build_runner build --delete-conflicting-outputs
For more information and generating code continuously see the documentation.
Flutter is declarative framework. This means that Flutter builds its user interface to reflect the current state of the app.
This template does not yet use a state management tool. Instead, each app service has an updates Stream that clients can subscribe to and receive state updates. It's up to you to use a tool of your choice, or don't use one at all.
See TasksRepository#taskEventUpdatesStream
and TasksRepository#taskGroupUpdatesStream
in TasksRepository
Dependencies are managed in the service_locator.dart
file. This sample uses GetIt, a lightweight service locator.
The test package contains unit tests for the TasksDataSource
and TasksRepository
:
- tasks_data_source_base_test - Base tests for every implementation; see tasks_cache_data_source_test that calls the base tests;
- tasks_repository_test - Tests the task and task group update streams:
TasksRepository#taskEventUpdatesStream
andTasksRepository#taskGroupUpdatesStream
; - tasks_stub_data_source - TasksDataSource stub;