Error 'A value of type 'dynamic' can't be assigned to a variable of type 'String'.' in Dart 2.2
Asked Answered
A

3

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

Atwater answered 7/3, 2019 at 7:54 Comment(2)
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/…Fortitude
I have the same issue, it's somehow related to AqueductScarification
D
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;
}
Dewan answered 7/3, 2019 at 8:41 Comment(1)
I am also stuck in similar case. Can you help in this question #63780222Puryear
E
0

use this:

analyzer:
  errors:
    invalid_assignment: ignore
Embayment answered 7/11, 2023 at 11:17 Comment(0)
M
0
analyzer:
  errors:
    argument_type_not_assignable: ignore <-- ADD THIS

This worked for me ✨

Also clean the cache of your IDE too

Melson answered 26/9 at 11:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.