Generate Offline
Generate Offline Data layers for @freezed model.xflutter_cli generate offline
Scenario study:
We have a Category @freezed model and we want to generate (create, read, update and delete) caching logic for this modelimport 'package:freezed_annotation/freezed_annotation.dart';
import '../media/media.dart';
part 'category.freezed.dart';
part 'category.g.dart';
@freezed
class Category with _$Category {
const factory Category({
int? id,
String? name,
List<Media>? media,
DateTime? createdAt,
DateTime? updatedAt,
}) = _Category;
factory Category.fromJson(Map<String, dynamic> json) => _$CategoryFromJson(json);
}
Result:
CLI provides two options to create the Flutter application Layer-Based Architecture and Feature-Based ArchitectureLayer-Based Architecture:
- xflutter_cli_test_application
- android
- assets
- ios
- lib
- data
- data_sources
- local
- categories
- models
- entities
- category
- repositories
- categories
Feature-Based Architecture:
- xflutter_cli_modules_application
- android
- assets
- ios
- lib
- modules
- categories
- data
- data_sources
- local
- categories
- models
- repositories
- categories
Usage:
Name | Type | Description | Example |
---|---|---|---|
src | option | specify one of the modules to execute command in (monorepo workspace or standalone modular-app) | |
path | option | generate data layer module path, used only with (modules-architecture) | modules/categories |
entity-name | option | name of entity for generating the data layer | |
primary-key | option | specify local-database entity with name of primary property, default is `id` | |
source | option | import file from specific module, this is helpful when you have multiple files with same name and one of them should be imported in the generated file, so you need to tell CLI which one should be imported | filename.dart:my_app1 |
sources | option | import file from multiple modules, this is helpful when you have multiple files with same name and many of them of them should be imported in the generated file, so you need to tell CLI which files should be imported | models.dart:my_package1, models.dart:my_package2 |