I have more than 100 posts inside a Scroll arrangement, and each post has its own CheckBox.
When a user checks a CheckBox (for example after copying a post), I want to save its state using TinyDB. The important part is that when the app is closed and reopened, the previously checked CheckBoxes should remain checked.
The problem is that I don’t want to create separate blocks for each CheckBox because there are too many of them (100+).
Is there any way to save Check Box simpley and shortly whit out creating lots of components?
During initialization, saves the TinyDB data into the variable savedData.
Initializes the Recycler List.
Generates a list of 500 items (“key_1”, “key_2”, etc.).
In .OnCreateView, it creates simple checkboxes
in .OnBindView it assigns the previously generated key as the text and sets Checked by retrieving the value from the savedData variable (if present, otherwise false).
Then we assign an ID to the checkbox
checkbox_dataitem = “checkbox_key_1”.
In WhenAnyCheckBox.Click (make sure to use .Click because it must be triggered by the user .Changed is also detected during creation with the Recycler List),
we retrieve the key name by removing “checkbox_” from the ID.
Finally, we save the checkbox state into a nested dictionary inside savedData, structured like this:
There are many other small improvements that could be made, but I’ll wait for your questions.
The WhenAny part is very similar for both RecyclerList and DynamicComponents, and I believe it’s the key part, together with generating the elements while retrieving the values from savedData.