This is a simple package to help build dart model from json.
About json file you can add some sign to assign default or nullable or not like this:
{
"r@id": 1,
"d@sex": 1,
"name": "Jack"
}you will get like this:
class ExampleModel {
final int id;
final int sex;
final String? name;
ExampleModel({required this.id, this.sex = 1, this.name})
}And you can use custom class List like this:
{
"list": "[]example"
}final List<ExampleModel> list;Also it support nested object like this:
{
"list": {
"length": 3,
"body": []
}
}It will auto generate a class named ListItemModel
- Add to your pubspec.yaml
dev_dependencies:
build_runner: any
json_dart:
git:
url: git://github.com/scnon/json_dart.git- You need put some json file to your jsons folder.like this:
├── jsons
│ ├── class.json
│ └── user.json
├── libs
│ └── main.dart- Just run it like this:
dart run build_runner build-
You will see you json model file in lib/models/
-
Enjoy it.