tomodels 1.0.0+2 tomodels: ^1.0.0+2 copied to clipboard
A simple json to dart models generator
Tomodels #
Tomodels is a simpel and powerfull json to dart generator.
this tools use https://github.com/javiercbk/json_to_dart to base engine with several customization
Features #
- API to JSON
- JSON to Dart
Installation #
Use global activate to install this package into your device :
dart pub global activate --source git https://github.com/alalawy/tomodels.git
Usage #
First, you must init the config to your project
tomodels init
after init the config, you can edit the config file at
├── tomodels
│ ├── config
│ │ ├── config.dart
config.dart
String jsonpath = "tomodels/json";
String modelspath = "tomodels/models";
List<Map<String, dynamic>> endpoint = [
{
"name": "",
"url": "",
"methods": "",
"headers": {"Content-Type": "application/json"},
"body": {}
}
];
you can change json path or models path directory.
For generate API to JSON just change the endpoint Map in config dart with yours
Example :
String jsonpath = "tomodels/json";
String modelspath = "tomodels/models";
List<Map<String, dynamic>> endpoint = [
{
"name": "product",
"url": "https://dummyjson.com/products/1",
"methods": "get",
"headers": {"Content-Type": "application/json"},
"body": {}
}
];
for methods you can change it to get, post, put or delete
.
After you change the config just run command :
tomodels create json
├── tomodels
│ ├── config
│ │ ├── config.dart
│ ├── json
│ │ ├── product.json
For generate JSON to Dart you must have file .json in the directory you specified in config.dart or you can generate it with the create json command
for generate models without generate json, you must change the name in Map endpoint at config.dart according to the name of your .json file
Example
String jsonpath = "tomodels/json";
String modelspath = "tomodels/models";
List<Map<String, dynamic>> endpoint = [
{
"name": "product",
"url": "",
"methods": "",
"headers": {"Content-Type": "application/json"},
"body": {}
},
{
"name": "category"
}, // if you just use this config to generate models from .json without fetching data, you can just type name like this without url, methods, etc
];
After you change the config just run
tomodels create models