https://kotlinlang.org logo
#compose
Title
# compose
l

Luca Nicoletti

09/01/2019, 10:05 AM
Hello, trying to achieve a Todo List in Compose, however, when I create a
@Model
class which has a list, adding elements to that list don’t trigger the drawing of the model on the screen. In order to have it working I added a
counter
to that model class. Increasing that
counter
whenever I add something to the list triggers the drawing of the model on the screen. (https://gist.github.com/lnicolet/039d2fe76e19e859582e32625ac411e7, https://gist.github.com/lnicolet/cb49c5a4021efc3b784bf95ec5755321). Working and not working examples in the links. Is there a different way to have it working with
lists
?
t

themishkun

09/01/2019, 1:06 PM
As far as I know,
@Model
tracks only changes of its properties. You are using
MutableList
, so you don't trigger property setter. Use
List
instead and you will be fine
l

Luca Nicoletti

09/01/2019, 1:32 PM
Thanks! Another question, how can I achieve tracking changes on items inside the list itself being propagated to the class which wraps the list? E.g.: changing the
isDone
to trigger an update
s

shikasd

09/01/2019, 4:12 PM
Not sure, but you can try to use
@Model
on such classes as well.
l

Luca Nicoletti

09/01/2019, 4:12 PM
I am already 🙂
t

themishkun

09/02/2019, 3:19 PM
@Luca Nicoletti I saw
@Pivotal
annotation does something like this
w

wasyl

10/22/2019, 8:46 AM
Hey @Luca Nicoletti Did you manage to get your list to work?