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>);
}
This PR is not perfect, it need to improved
After some discovery phase in the past week or so, the above issue doesn't seem to exhibit itself on most systems.
I do get the missing bracket but also on my system, it appears as if the script is failing to correctly identify if the variable is a primitive or not causing an additional cast to be made.
The end result is an additional cast in fromMap on my Linux system but the problem isn't observable by at least two individuals with Windows and MacOS respectively.
I have to wonder if the two are connected - the missing bracket and the failed !isPrimitive triggering the cast?
I'm not sure how to proceed and what information to gather in regards to the extension or the JS environment that might affect the VS Code.