Dart-Data-Class-Generator
Dart-Data-Class-Generator copied to clipboard
from map has extra opening bracket
How to reproduce the error?
Please generate the model for this class
class User {
String name;
List<String> children;
}
The generated model will look something like this. In User.fromMap
we have invalid code List<String>.from((map['children'] as List<String>)
There is one extra opening parentheses
import 'dart:convert';
class User {
String name;
List<String> children;
User({
required this.name,
required this.children,
});
Map<String, dynamic> toMap() {
return <String, dynamic>{
'name': name,
'children': children,
};
}
factory User.fromMap(Map<String, dynamic> map) {
return User(
name: map['name'] as String,
children: List<String>.from((map['children'] as List<String>),
);
}
String toJson() => json.encode(toMap());
factory User.fromJson(String source) => User.fromMap(json.decode(source) as Map<String, dynamic>);
}