df_generate_dart_models 0.10.1 df_generate_dart_models: ^0.10.1 copied to clipboard
A tool for generating data models and classes from annotations, offering greater flexibility than json_serializable or freezed.
DF - Generate Dart Models (DFMDL) #
Dart & Flutter Packages by DevCetra.com & contributors.
Summary #
A tool for generating data models and classes from annotations, offering greater flexibility than json_serializable or freezed. It supports generating classes from template files for enhanced customization, ensures stronger type safety, and includes intelligent conversion mechanisms.
Below are some basic steps to get you started with this package. This package is designed to work with the df_generate_dart_models_core
package, which provides the core functionality for generating models.
The example below provides a glimpse of what this package can do. The package includes advanced features such as AI-driven generation, customizable type mappers, template files, model conversion to other programming languages, and mor but these advanced features are still in development and not yet documented. Feel free to contact the developer if you require more information.
Quickstart #
Step 1 #
To install this tool, run dart pub global activate df_generate_dart_models 0.9.3
in your terminal. You can replace 0.9.3
with any other version or omit it to install the latest version. It’s recommended to specify a version to avoid potential issues from frequent updates and changes.
Step 2 #
Add df_generate_dart_models_core
to your pubspec.yaml
file.
dependencies:
df_generate_dart_models_core: 0.6.9 # Fixed version to ensure compatibility and avoid issues from frequent updates.
Step 3 #
Create a template for your model, for example:
// Import the annotation GenerateDartModel, Field, and the Model class, etc.
import 'package:df_generate_dart_models_core/df_generate_dart_models_core.dart';
// This file may not yet exist but will be generated.
part '_model_user.g.dart';
// Define the model to generate.
@GenerateDartModel(
fields: {
Field(
fieldPath: ['id'],
fieldType: String,
),
Field(
fieldPath: ['firstName'], // the field key
fieldType: String, // the field type
nullable: true, // whether the field can be null or not
),
Field(
fieldPath: ['lastName'],
fieldType: String,
nullable: true,
),
},
shouldInherit: true, // lets extend some base class
)
// Since `shouldInherit` is true, the generated model will know to extend this class.
abstract class _ModelUser extends Model {
const _ModelUser();
}
// We can add some extension methods to the generated model.
extension ModelUserX on ModelUser {
String fullName() {
return '${this.firstName} ${this.lastName}';
}
}
Step 4 #
Save the file somewhere in its own directory, for example lib/models/model_user/model_user.dart
.
Step 5 #
Open the terminal and navigate to lib/models/model_user
, then run dfmdl
. This will generate the _model_user.g.dart
file in the same directory. In editors like VS Code, you can right-click on the folder and select “Open in Integrated Terminal” to open the terminal directly at the desired location, and then run dfmdl
to generate the file.
Contributing and Discussions #
This is an open-source project, and we warmly welcome contributions from everyone, regardless of experience level. Whether you're a seasoned developer or just starting out, contributing to this project is a fantastic way to learn, share your knowledge, and make a meaningful impact on the community.
Ways you can contribute: #
- Buy me a coffee: If you'd like to support the project financially, consider buying me a coffee. Your support helps cover the costs of development and keeps the project growing.
- Share your ideas: Every perspective matters, and your ideas can spark innovation.
- Report bugs: Help us identify and fix issues to make the project more robust.
- Suggest improvements or new features: Your ideas can help shape the future of the project.
- Help clarify documentation: Good documentation is key to accessibility. You can make it easier for others to get started by improving or expanding our documentation.
- Write articles: Share your knowledge by writing tutorials, guides, or blog posts about your experiences with the project. It's a great way to contribute and help others learn.
No matter how you choose to contribute, your involvement is greatly appreciated and valued!
Chief Maintainer: #
📧 Email Robert Mollentze at robmllze@gmail.com
Dontations: #
If you're enjoying this package and find it valuable, consider showing your appreciation with a small donation. Every bit helps in supporting future development. You can donate here:
https://www.buymeacoffee.com/robmllze
License #
This project is released under the MIT License. See LICENSE for more information.