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

16,286
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;
}
Share:
16,286
Francesco Iapicca
Author by

Francesco Iapicca

Self taught developer in love with Flutter and Dart

Updated on July 06, 2022

Comments

  • Francesco Iapicca
    Francesco Iapicca almost 2 years

    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

  • Roxx
    Roxx almost 4 years
    I am also stuck in similar case. Can you help in this question stackoverflow.com/questions/63779722/…