Is there a way to dynamically call a method or set an instance variable in a class in Dart?
问题 I would want to be able to do something like this with a Dart class constructor: class Model { // ... setting instance variables Model(Map fields) { fields.forEach((k,v) => this[k] = v); } } Obviously, this doesn't work, because this doesn't have a []= method. Is there a way to make it work or is it simply not "the dart way" of doing things? If it's not, could you show me what would be the right way to tackle this? 回答1: Currently no. You will have to wait for reflection to arrive in Dart