jonataslaw / jonataslaw/get_cli

I really like get generate model

Open
#241 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Dart
Stars
654
Forks
193
PR merge metrics
No merged PRs in 30d

Description

The JSON returned by the server is sometimes non-standard, such as:

user.json
```
[{
"name": "",
"age": 0,
"discount": 0,
"friends": []
},{
"name": "",
"age": 0,
"discount": 0.0,
"friends": []
}]
```

Run:get generate model on home with assets/models/user.json

output:
```
class User {
String? name;
int? age;
double? discount;
List? friends;

User({this.name, this.age, this.discount, this.friends});

User.fromJson(Map json) {
name = json['name'];
age = json['age'];
discount = json['discount'];
if (json['friends'] != null) {
friends = [];
json['friends'].forEach((v) {
friends?.add(Null.fromJson(v));
});
}
}

Map toJson() {
final data = {};
data['name'] = name;
data['age'] = age;
data['discount'] = discount;
if (friends != null) {
data['friends'] = friends?.map((v) => v.toJson()).toList();
}
return data;
}
}
```

flutter run:
[Error: fluent/runtime/start_vm_initializer. cc (41)] Unhandled Exception: type 'int' is not a subtype of type 'double?'

I will double? Change to num? After solving this problem, how do I mention int when generating the model Double? Unified replacement with num? Type?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.