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

Francesco Iapicca
  • 2,618
  • 5
  • 40
  • 85
  • 6
    You can disable this check by removing `implicit-cast: false` (or setting it to true) from the `analysis.options.yaml` file. https://www.dartlang.org/guides/language/analysis-options#enabling-additional-type-checks – Mattia Mar 07 '19 at 14:46
  • I have the same issue, it's somehow related to Aqueduct – Elia Weiss Feb 28 '21 at 15:14

1 Answers1

12
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;
}
mezoni
  • 10,684
  • 4
  • 32
  • 54
  • I am also stuck in similar case. Can you help in this question https://stackoverflow.com/questions/63779722/flutter-add-comma-separated-value-to-class-list – Roxx Sep 07 '20 at 16:08