How to construct a class with named args from a map? How to construct a class with named args from a map? dart dart

How to construct a class with named args from a map?


By creating a constructor for that matter:

class Person {  final int age;  final String name;  const Person({    @required this.age,    @required this.name,  });   Person.fromMap(Map<String, dynamic> map) : age = map['age'],        name = map['name'];}

You can also assign in the constructor body if you prefer, that makes it more clear if you have more fields.