SanjaySodani / json_editor_flutter

A user friendly widget to edit JSON object.
BSD 3-Clause "New" or "Revised" License
8 stars 2 forks source link

onChanged method is called with the reference of the internal json #2

Closed ArinFaraj closed 2 months ago

ArinFaraj commented 8 months ago

The json (_data) returned in the onChanged method is the same object that is manipulated in the JsonEditor. Therefore, if you assign the json returned in the onChanged method to some variable somewhere and continue with more edits in the JsonEditor, the variable outside would also be changed as it's assigned by reference.

To fix this issue, you should not send the (_data) to onChanged method immediately. Instead, copy it with _data is Map ? {...(_data as Map)} : [..._data] or with a better way and then send it to onChanged.

SanjaySodani commented 2 months ago

@ArinFaraj, Thank you for reporting this!

I will fix this issue in this next version.