Skip to content
This repository was archived by the owner on May 29, 2023. It is now read-only.

from map has extra opening bracket #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nitishk72
Copy link

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>);
}

@nitishk72
Copy link
Author

This PR is not perfect, it need to improved

@psstoyanov
Copy link

psstoyanov commented Nov 16, 2022

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants