-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
Hello and first of: Thanks for these great packages!
Problem Statement
Currently, the generator requires models with nullable fields to represent form state, forcing developers to maintain two parallel models:
- A domain model with proper nullability representing the business logic
- A form state model with nullable fields for form handling
This leads to unnecessary duplication and makes it harder to maintain type safety between form submissions and domain objects.
Example of current approach:
// Domain Model
class User {
final String name; // Required in domain
final String email; // Required in domain
final String? phoneNumber;
}
// Currently needs manual form model
class UserFormModel {
final String? name; // Must be nullable for form
final String? email; // Must be nullable for form
final String? phoneNumber;
}Proposed Enhancement
The generator should automatically generate both:
- The form model class with appropriate nullable fields
- An extension method on the domain model for conversion
The @Rf annotation should support configuring partial data injection through related models.
Example Usage
// Domain model with partial data configuration
@Rf(partialData: {
'UserInvitation': {
'email': 'email' // maps invitation.email to userFormModel.email
}
})
class User {
final String name;
final String email;
final String? phoneNumber;
}
// Generated form model with inferred validators
class UserFormModel {
final String? name; // Generated with RequiredValidator() since non-nullable in User
final String? email; // Generated with RequiredValidator() since non-nullable in User
final String? phoneNumber; // No RequiredValidator() since nullable in User
}
// Generated extension
extension UserFormExtension on User {
UserFormModel get formModel => UserFormModel(
name: name,
email: email,
phoneNumber: phoneNumber,
);
}
// Usage in UI
UserFormBuilder(
// Optional initial data from domain model using generated extension
model: existingUser?.formModel,
// Partial data injection configured by @Rf annotation
userInvitation: UserInvitation(email: "example@email.com"),
builder: (context, form, child) => ...
)
Benefits
- Reduces boilerplate and maintenance overhead
- Maintains single source of truth for model structure
- Preserves type safety throughout the form lifecycle
- Enables better IDE support and static analysis
- Allows seamless integration with domain-driven design practices
- Provides clean, intuitive API through generated extensions on domain model class
- Declarative configuration of partial data injection
- Automatic validation rules based on domain model nullability
Implementation Notes
The generator would need to:
- Analyze domain model field nullability
- Parse
@Rfannotation for partial data configuration - Generate form state model with nullable fields
- Generate validation rules based on domain model nullability
- Generate extension methods for converting domain models to form models
- Generate partial data injection logic based on annotation configuration
Would you consider this enhancement for a future release? It would significantly improve the developer experience when working with domain-driven architectures.
Metadata
Metadata
Assignees
Labels
No labels