entityfy_generator 3.0.2 copy "entityfy_generator: ^3.0.2" to clipboard
entityfy_generator: ^3.0.2 copied to clipboard

Code generator for creating extension methods to map model classes to entity classes using annotations.

example/lib/main.dart

import 'generator_showcase.dart';

void main() {
  print('=== Entityfy Generator - Fake Data Showcase ===\n');

  // Example: Fake Data Generation - NEW FEATURE!
  print('šŸš€ Generating fake data for testing:\n');

  // Generate fake transportation data
  print('šŸ“¦ Transportation Data:');
  final fakeTransportations = TransportationEntity.fakeList(count: 5);
  print(
    '   Generated ${fakeTransportations.length} fake transportation entities:',
  );
  for (int i = 0; i < fakeTransportations.length; i++) {
    final transport = fakeTransportations[i];
    print(
      '   ${i + 1}. ${transport.brand} ${transport.model} (${transport.year})',
    );
    print('      Plate: ${transport.plateNumber} | VIN: ${transport.vin}');
    print(
      '      Color: ${transport.color} | Axles: ${transport.axles} | Active: ${transport.isActive}',
    );
  }
  print('');

  // Generate fake product data
  print('šŸ›ļø Product Data:');
  final fakeProducts = ProductEntity.fakeList(count: 3);
  print('   Generated ${fakeProducts.length} fake product entities:');
  for (int i = 0; i < fakeProducts.length; i++) {
    final product = fakeProducts[i];
    print(
      '   ${i + 1}. ${product.name} - \$${product.price.toStringAsFixed(2)}',
    );
    print('      Description: ${product.description}');
    print('      Available: ${product.isAvailable} | Tags: ${product.tags}');
    print('      Created: ${product.createdAt.toString().substring(0, 10)}');
  }
  print('');

  // Demonstrate custom count
  print('šŸ”¢ Custom Count Example:');
  final manyProducts = ProductEntity.fakeList(count: 100);
  print('   Generated ${manyProducts.length} products for load testing');

  final manyTransports = TransportationEntity.fakeList(count: 50);
  print(
    '   Generated ${manyTransports.length} transportation units for simulation',
  );
  print('');

  // Show JSON serialization of fake data
  print('šŸ“„ JSON Serialization:');
  final sampleProduct = fakeProducts.first;
  print('   Sample product as JSON:');
  print('   ${sampleProduct.toJson()}');
  print('');

  print('=== Fake Data Use Cases ===');
  print('āœ… Unit testing with consistent mock data');
  print('āœ… UI development with placeholder content');
  print('āœ… Load testing with large datasets');
  print('āœ… Demo environments with realistic data');
  print('āœ… Database seeding for development');
  print('āœ… API testing with varied scenarios');

  print('\nšŸ“ How to use:');
  print('1. Add @Entityfy(generateFakeList: true) to your model');
  print('2. Run: dart run build_runner build');
  print('3. Use: YourEntityFakeData.fakeList(count: 20)');
}

void demonstrateModels() {
  // Create sample data
  final author = AuthorModel(
    id: 'author-1',
    name: 'John Developer',
    email: 'john@dev.com',
    bio: 'Passionate Dart developer',
    socialLinks: ['https://github.com/john', 'https://twitter.com/john'],
  );

  final blogPost = BlogPostModel(
    id: 'post-1',
    title: 'Getting Started with Entityfy',
    content: 'This is a comprehensive guide...',
    authorId: author.id,
    tags: ['dart', 'code-generation', 'entityfy'],
    publishedAt: DateTime.now().subtract(Duration(days: 2)),
    updatedAt: DateTime.now().subtract(Duration(hours: 5)),
    isPublished: true,
    viewCount: 150,
  );

  final comment = CommentModel(
    id: 'comment-1',
    content: 'Great article! Very helpful.',
    blogPostId: blogPost.id,
    author: author,
    createdAt: DateTime.now().subtract(Duration(hours: 1)),
    replies: [],
  );

  final category = CategoryEntity(
    id: 'cat-1',
    name: 'Dart Development',
    description: 'All about Dart programming',
    color: '#0175C2',
    postCount: 42,
  );

  print('šŸ“„ Original Models Created:');
  print('  - BlogPostModel: "${blogPost.title}"');
  print('  - AuthorModel: "${author.name}"');
  print('  - CommentModel: "${comment.content}"');
  print('  - CategoryEntity: "${category.name}"');

  print('\nšŸ”„ After running build_runner, you can use:');
  print('  - blogPost.toEntity() → BlogPostEntity');
  print('  - blogPost.toEntity().toUiModel() → BlogPostUiModel');
  print('  - author.toEntity() → AuthorEntity');
  print(
    '  - comment.toEntity() → CommentEntity (with nested author conversion)',
  );
  print('  - category.toUiModel() → CategoryUiModel');

  print('\n✨ The generator will create:');
  print('  • Entity classes with fromJson/toJson methods');
  print('  • UI Model classes optimized for UI display');
  print('  • Extension methods for seamless conversion');
  print('  • Automatic handling of nested model conversions');
  print('  • Support for Lists, nullable types, and DateTime');
}
0
likes
150
points
60
downloads

Documentation

Documentation
API reference

Publisher

verified publishercposadadev.com

Weekly Downloads

Code generator for creating extension methods to map model classes to entity classes using annotations.

Repository (GitHub)
View/report issues

Topics

#code-generation #entity-mapping #data-transformation #annotations #source-gen

License

MIT (license)

Dependencies

analyzer, build, entityfy, source_gen

More

Packages that depend on entityfy_generator