8

since the last dart update (2.2) I'm getting this error,

'A value of type 'dynamic' can't be assigned to a variable of type 'String'.'

which doesn't make much sense to me. the code is absolutely trivial:

    class EmployeeMirror {
  EmployeeMirror(this.id, this.name);

  EmployeeMirror.fromMap(Map<String, dynamic> _map) {
    id = _map['id'];      // error here
    name = _map['name'];  // and here
  }

  int id;
  String name;
}

I don't think is relevant, but this is in an Aqueduct project.

thanks in advance for the help

2
  • 6
    You can disable this check by removing implicit-cast: false (or setting it to true) from the analysis.options.yaml file. dartlang.org/guides/language/… Commented Mar 7, 2019 at 14:46
  • I have the same issue, it's somehow related to Aqueduct Commented Feb 28, 2021 at 15:14

3 Answers 3

13
class EmployeeMirror {
  EmployeeMirror(this.id, this.name);

  EmployeeMirror.fromMap(Map<String, dynamic> _map) {
    id = _map['id'] as int;
    name = _map['name'] as String;
  }

  int id;
  String name;
}
Sign up to request clarification or add additional context in comments.

1 Comment

I am also stuck in similar case. Can you help in this question stackoverflow.com/questions/63779722/…
0

use this:

analyzer:
  errors:
    invalid_assignment: ignore

Comments

0
analyzer:
  errors:
    argument_type_not_assignable: ignore <-- ADD THIS

This worked for me ✨

Also clean the cache of your IDE too

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.