Relative Content

Tag Archive for androidjsonflutterdartflutter-dependencies

Json_Annotation does not handle nested classes properly

I have nested classes InventoryResult and Item that I want to read/write with json files, and the generated code by json_annotation does not map Item list in the toJson() method; curiously handling is totally fine for fromJson() method.
Below are my 2 classes:

Flutter Inventory Management: Read from a json assets file, write to a local file and add to a Riverpod managed list of items

I am trying to learn Flutter through implementation of an inventory app. My app currently reads a list of items from a json file, managed by riverpod, this part works. I also read that Flutter does not allow writing to assets, so I wrote an insertItem() method that writes to a local file and also adds the new item to the managed current Items list. Neither of them are being generated, with no errors. I just see ‘Item Added’ snack bar, Inventory List is same in the inventory list screen and also file is not in the local device file explorer. I will try to briefly add the relevant parts of the code, let me know if wish to see some other parts. Reading from Json assets file part works fine.