ClojureDart: How to pass data to parent state widget?

Viewed 35

I have a Scaffold parent widget where I defined a variable transforms that contains a vector of Offset. The child widget is supposed to display those points with CustomPainter. For now, I just passed my variable transforms as an argument to the child widget.

The problem is, I want to add an element to my vector each time we pressed the floatingActionButton, which is written in my parent widget ; and when I click on it, it does not appear on the screen (the child doesn't get the information).

So how to make widgets communicate?

1 Answers

The answer is pretty simple. The way for a widget to inherit informations from another, is to used the f/widget function and the :inherit keyword. Example:

(f/widget
:inherit [m/Theme]
)

In order to inherit from the Theme widget and its internal state data. But that is not it, in the parent widget you want to make your data available/sharable, you have to define your data in the :bind map. Example:

(def child
  (f/widget
    :inherit [:transforms]
;; don't forget to dereference it when you want to use it
;; (dart:core/print @transforms)
...))

(def parent
  (f/widget
    :bind {:transforms [(m/Offset 0 0) (m/Offset 1 0)]}
...))

Related