Cithakan comes from the Javanese language, meaning "Template". This project is a collection of templates designed to accelerate Flutter application development by leveraging the power of Mason.
Ensure that you have Mason installed before using Cithakan. If not, install it with the following command:
dart pub global activate mason_cli
Then, add Cithakan to Mason by running:
mason add <BRICK_NAME> -g --git-url https://github.com/geekswamp/cithakan --git-path bricks/<BRICK_NAME>
For example:
mason add bloc -g --git-url https://github.com/geekswamp/cithakan --git-path bricks/bloc
Available bricks:
After installation, you can generate a template using the following command:
mason make <BRICK_NAME>
For example:
mason make bloc
Follow the on-screen instructions to customize the template to your project's needs.
Important
The naming of BLoC States follows this official BLoC naming conventions documentation, but this is optional. Feel free to use whatever naming conventions you prefer.
If you're using freezed
with json_serializable
, recent versions of json_serializable
and meta may need you to disable the invalid_annotation_target
warning. To do this, add the following to the analysis_options.yaml
file at the root of your project:
analyzer:
errors:
invalid_annotation_target: ignore
- dio is a powerful HTTP client for Dart, used for making network requests with features like interceptors, request cancellation, and automatic retries.
- envied is used for managing environment variables securely within the Flutter application.
- fpdart is a functional programming library for Dart that provides powerful monads like Either, Option, and Task to improve code safety and maintainability.
- freezed helps in generation immutable classes and union types, making data modeling and serialization easier.
- flutter_secure_storage is used for securely storing sensitive data, such as authentication tokens and user credentials, using platform-specific encrypted storage.
- flutter_bloc is used for state management, providing a predictable way to manage application state using the BLoC pattern.
- get_it is a simple yet powerful service locator for Dart, used to manage dependencies efficiently without relying on Flutterβs
BuildContext
. - injectable is used for dependency injection, allowing for a modular and testable codebase.
- json_serializable is used to automate the serialization and deserialization of JSON data, reducing boilerplate code and ensuring type safety.
freezed
does not allow inheriting from its generated classes. Instead of inheritance, it is recommended to use composition (source). For example:
// You can find this class in lib/cores/use_case.dart.
@freezed
class QueryParams with _$QueryParams {
const QueryParams._();
const factory QueryParams({
@Default(0) int? offset,
@Default(10) int? limit,
@Default(1) int? page,
@Default(SortOrder.asc) SortOrder? sortOrder,
String? search,
}) = _QueryParams;
Map<String, dynamic> toJson() {
return Map<String, dynamic>.fromEntries(
{
'offset': offset,
'limit': limit,
'page': page,
'search': search,
'order': sortOrder?.value,
}.entries.where((e) => e.value != null)
);
}
}
// freezed doesn't support inheritance, use composition instead.
@freezed
class OtherParams with _$OtherParams {
const factory OtherParams({
required int id,
required QueryParams queryParams,
}) = _OtherParams;
}
A generated project using Cithakan follows this structure:
lib/
βββ cores/
β βββ di/
β β βββ di.dart
β βββ env/
β β βββ env.dart
β βββ network/
β β βββ dio_client.dart
β β βββ dio_client_impl.dart
β β βββ network_interceptor.dart
β βββ storage/
β β βββ base_storage.dart
β β βββ secure_storage.dart
β βββ failure.dart
β βββ isolate_parser.dart
β βββ modules.dart
β βββ use_case.dart
βββ datas/
β βββ locals/
β β βββ data_sources/
β β β βββ some_local_data_source/
β β β βββ some_local_data_source.dart
β β βββ repositories/
β β βββ some_repository/
β β βββ some_repository_impl.dart
β βββ remotes/
β βββ data_sources/
β β βββ some_remote_data_source/
β β βββ some_remote_data_source.dart
β βββ repositories/
β βββ some_repository/
β βββ some_repository_impl.dart
βββ domains/
β βββ models/
β β βββ some_model.dart
β βββ repositories/
β β βββ some_repository/
β β βββ some_repository.dart
β βββ usecases/
β βββ some_usecase/
β βββ some_usecase.dart
βββ presentations/
βββ blocs/
β βββ some/
β βββ some_bloc.dart
β βββ some_event.dart
β βββ some_state.dart
βββ cubits/
βββ some/
βββ some_cubit.dart
βββ some_state.dart