markgravity / object_mapper

Object Mapper for Flutter
8 stars 3 forks source link

How to update value of object #5

Closed mq162 closed 3 years ago

mq162 commented 3 years ago

I write a function to update value of my object but when I get the value it's always return null :(

class User with Mappable { String name; String email;

@override void mapping(Mapper map) { map("name", name, (v) => name = v); map("email", email, (v) => email = v); }

updateValue({required String key, dynamic value}) { var json = toJson(); json[key] = value; var map = Mapper.fromJson(json); mapping(map); } }