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)

Description: Path to JSON file for model generation

Usage:

Benefits:

  • Local file processing

  • Offline development

  • Version controlled schemas


--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)

Description: Choose starter template for model generation

Format: basic|custom

Available Options:

  • basic → Simple model generation with minimal configuration

  • custom → Interactive template with guided options

Usage:


--style (-s)

Description: Choose model generation style

Format: plain|json|freezed

Available Options:

  • plain → Simple Dart classes

  • json → JSON serializable models with toJson/fromJson

  • freezed → Immutable data classes with code generation

Usage:


--on

Description: Specify subdirectory path for model placement

Format: path/to/directory (max 3 levels)

Usage:


🚩 Flags

--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)

Description: Generate immutable model with final fields

Usage:

Generated Code:


--copyWith (-c)

Description: Add copyWith method for creating modified copies

Usage:

Generated Code:


--equatable (-e)

Description: Use Equatable package for value equality comparison

Usage:

Generated Code:


--force

Description: Force overwrite existing files without prompting

Usage:


🎯 Common Workflows

🚀 Quick API Integration

🏗️ Complex Model with Relationships

🔄 Iterative Development


💡 Best Practices

🎯 Model Organization

  1. Use --on for logical grouping: Group related models in subdirectories

  2. Enable --relationships-in-folder: Keep complex models organized

  3. Use descriptive names: Choose clear, descriptive model names

🔧 Feature Selection

  1. Start with --style json: Good for API integration

  2. Add --immutable --copyWith: For state management

  3. Use --equatable: For value comparison in lists/sets

  4. Upgrade to --style freezed: For production apps

🛡️ Development Workflow

  1. Test with small JSON first: Validate structure before complex models

  2. Use --force during development: Quick iteration

  3. Version control your JSON: Track schema changes

  4. 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