Model
π Description
Generate type-safe Dart model files from JSON sources with advanced features like nested relationships, serialization, immutability, and complex data structures. Perfect for API integration and data modeling.
βοΈ Usage
gexd make model [<name>] [options]π Key Features
π― Multiple Data Sources
JSON Files: Generate from local JSON files
API Endpoints: Fetch and generate from live APIs
Interactive Templates: Guided model creation
ποΈ Advanced Architecture Support
GetX Templates: Modular feature-based architecture
Clean Architecture: Domain-driven design with layered structure
Custom Organization: Flexible subdirectory placement
π§ Model Features
Type Safety: Automatic type detection and conversion
Nested Objects: Complex relationship handling
Immutable Models: Thread-safe data structures
Serialization: JSON to/from Dart conversion
Equatable Integration: Value equality comparison
π Relationship Management
Automatic Detection: Smart identification of nested objects
Separate Folder Generation: Organized relationship files
Dependency Resolution: Proper import management
π Detailed Usage
π― Real-World Examples
π Example JSON Input
Create a file assets/models/user.json:
ποΈ Basic Model Generation
Generated Files:
π¨ Advanced Model with All Features
Generated Code Example:
π API-Based Model Generation
βοΈ Options
--file (-f)
--file (-f)Description: Path to JSON file for model generation
Usage:
Benefits:
Local file processing
Offline development
Version controlled schemas
--url (-u)
--url (-u)Description: URL to fetch JSON data for model generation
Usage:
Benefits:
Live API integration
Real-time schema updates
Production data structures
--template (-t)
--template (-t)Description: Choose starter template for model generation
Format: basic|custom
Available Options:
basicβ Simple model generation with minimal configurationcustomβ Interactive template with guided options
Usage:
--style (-s)
--style (-s)Description: Choose model generation style
Format: plain|json|freezed
Available Options:
plainβ Simple Dart classesjsonβ JSON serializable models with toJson/fromJsonfreezedβ Immutable data classes with code generation
Usage:
--on
--onDescription: Specify subdirectory path for model placement
Format: path/to/directory (max 3 levels)
Usage:
π© Flags
--relationships-in-folder (-r)
--relationships-in-folder (-r)Description: Generate nested objects in separate organized folder structure
Default: true
Usage:
Output Structure:
Benefits:
Clean Organization: Separate files for each nested object
Better Maintainability: Easy to locate and modify specific models
Import Management: Automatic import handling
Scalability: Handles complex nested structures gracefully
--immutable (-i)
--immutable (-i)Description: Generate immutable model with final fields
Usage:
Generated Code:
--copyWith (-c)
--copyWith (-c)Description: Add copyWith method for creating modified copies
Usage:
Generated Code:
--equatable (-e)
--equatable (-e)Description: Use Equatable package for value equality comparison
Usage:
Generated Code:
--force
--forceDescription: Force overwrite existing files without prompting
Usage:
π― Common Workflows
π Quick API Integration
ποΈ Complex Model with Relationships
π Iterative Development
π‘ Best Practices
π― Model Organization
Use
--onfor logical grouping: Group related models in subdirectoriesEnable
--relationships-in-folder: Keep complex models organizedUse descriptive names: Choose clear, descriptive model names
π§ Feature Selection
Start with
--style json: Good for API integrationAdd
--immutable --copyWith: For state managementUse
--equatable: For value comparison in lists/setsUpgrade to
--style freezed: For production apps
π‘οΈ Development Workflow
Test with small JSON first: Validate structure before complex models
Use
--forceduring development: Quick iterationVersion control your JSON: Track schema changes
Document your models: Add comments for complex relationships
π§ Troubleshooting
β Common Issues
Issue: Nested objects not generating properly
Issue: Complex API responses
Issue: Existing files conflict
Generated automatically by gexd_doc
Last updated