matrix

Benjamin C 2023-06-05T04:24:40.974709Z

I think I'm missing something:

(defn button [title action]
  (fx/gesture-detector
   {:onTap (fx/as-dart-callback [] (action))}
   (fx/center
    (m/Text title .style (m/TextStyle .fontSize 18 .fontWeight m/FontWeight.w800)))))

(defn make-app []
  (let [title "Why Hello"]
    (fx/material-app
     {:title title}
     (fx/scaffold
      {:appBar (fx/app-bar {:title (fx/text title)})}
      {:name :scaffo
       :step (cI 1)}
      (fx/center
       (fx/column
        (fx/text (str "current step: " (mget (fasc :scaffo) :step)))
        (fx/elevated-button {:onPressed (dfn [] (with-cc :test (mset! (fasc :scaffo) :step 2)))}
                            (fx/text "Change to next step"))
        (fx/elevated-button {:onPressed (dfn [] (with-cc :test (mset! (fasc :scaffo) :step 1)))}
                            (fx/text (str "Change to first step")))
        (case (mget (fasc :scaffo) :step)
          1 (fx/column (fx/text "hi -- ")
                       (button "you'd think this would change" (fn [] (mx/dp :button-1))))
          2 (fx/column (fx/text "howdy -- ")
                       (button "but does it?" (fn [] (mx/dp :button-2)))))))))))
The regular text (IE. "hi -- " and "howdy -- ") Changes with the :step prop, as I would expect. Yet somehow the (button ,,,,) call does not?

👀 1
kennytilton 2023-06-05T12:03:52.904219Z

Gonna fire this up now....

kennytilton 2023-06-05T12:42:42.238419Z

Confirmed the issue. Oh, btw, it should not matter (it's a NOP), but we only need to wrap state change in with-cc in watches, when a state change is already underway. So the gesture-detector :onTap is fine. But I have those commented out in the elevated button onPresses and the problem is unchanged. I will leave them commented out while I explore, just to KISS. I suspect I may be missing a setState. Deep-diving...

kennytilton 2023-06-05T13:20:08.145049Z

Confirm it works without the gesture-detector -- good clue! Just realizing how strange is the behavior -- the text hi/howdy proves we are changing columns! Btw, eliminating the "but does it?" button altogether works in the sense that "you'd think" disappears. Good one! Wondering if we are looking at two issues... 🤔

kennytilton 2023-06-05T13:45:41.175569Z

OK, the second column runs as expected, and as we can see from the text being pulled in. I have to crash, but methinks Flutter thinks the two GDs (gesture detectors) are the same, for some value of "same". More after a quick crash.

Benjamin C 2023-06-05T15:38:35.500469Z

Sounds likely! Some bits in this thread are perhaps relevant: https://clojurians.slack.com/archives/C03A6GE8D32/p1675818632237609

Benjamin C 2023-06-05T16:02:20.847719Z

Hmm, maybe it has something to do with GuestureDetector being a StatelessWidget ?

Benjamin C 2023-06-05T16:04:05.324079Z

Since we're not dealing with a stateful widget, maybe we need to call markNeedsBuild directly?

kennytilton 2023-06-05T16:16:58.789759Z

Thx, I have been getting ready to explore which widgets were stateless and which not. I think I have experimented enough with widget juggling, I'll see where I can work markNeedsBuild into things.

Benjamin C 2023-06-05T16:17:56.020209Z

Ooh, wait, this might be a very simple fix, this deftag looks suspicious...

Benjamin C 2023-06-05T16:18:09.737449Z

(deftag tiltontec.flutter-mx.factory/k1-child-stateful gesture-detector m/GestureDetector)

Benjamin C 2023-06-05T16:24:44.518569Z

@hiskennyness Aha, that's the culprit! swapped with k1-child-stateless and now it works like a charm :)

👏 1
kennytilton 2023-06-05T16:31:32.045139Z

Great catch, and the Flutter doc confirms I got that wrong. Now I have to cheak Ink, because a center/ink/text is also broken, no GD at all.

Benjamin C 2023-06-05T16:36:29.866759Z

Not sure about Ink itself, but InkWell is stateless, so probably same for Ink? I wish flutter gave us a simpler way to find out :P

Benjamin C 2023-06-05T16:50:38.989509Z

Oh, yeah, InkWell is indeed stateful, (in accordence with the deftag), so something else must be at play.

kennytilton 2023-06-05T16:51:43.167799Z

Ink seems to be either. No inheritance (I scroll waaayyyyyyyy down to an inheritance list) and see neither Stateful nor Stateless.

Benjamin C 2023-06-05T16:52:23.413379Z

Oh you're right, I got my pages mixed up for a sec.

kennytilton 2023-06-05T16:52:28.194039Z

ISTR Text is the same.

Benjamin C 2023-06-05T16:53:57.606099Z

Hmm, (deftag tiltontec.flutter-mx.factory/k1-child-stateless ink m/Ink) work?

kennytilton 2023-06-05T16:55:26.386759Z

With text I covered all the bases:

(deftagleaf tiltontec.flutter-mx.factory/konly-param1-stateless text m/Text)
(deftagleaf tiltontec.flutter-mx.factory/konly-param1-stateful text! m/Text)

kennytilton 2023-06-05T16:56:03.569259Z

And ISTR that was necessitated by sth not updating.

Benjamin C 2023-06-05T17:05:22.769739Z

The Joy of Clojure Flutter :P

Benjamin C 2023-06-05T17:17:15.288749Z

Maybe taking a more direct approach of markNeedsBuild instead of setState might work around the flutter dance?

Benjamin C 2023-06-05T17:17:44.722729Z

Would need some extra guards in the mx internals, I'd guess, but might be a universal solution.

Benjamin C 2023-06-05T17:22:26.811669Z

(I really have little context to work with here, this is just me stabbing in the dark)

kennytilton 2023-06-05T17:26:51.064579Z

So far I have found Flutter and Dart to be a PITA to get to work, but eventually sort it out in a way that makes sense. Then I get to look at mobile, desktop, and Web. 🙂 And f/mx can hide the nuisance. With other tools, the pain never ends, we just soldier on grumbling. Are you able to toggle back and forth OK. What if you hit the first button twice, then hit the second? I am seeing:

The following assertion was thrown while handling a gesture:
md-awaken> incoming md-state not= :nascent, it is:md-quiesced
re mNB vs setState, I felt ss might be more "within the system". But mnb is part of the API, and perhaps better than agonizing over stateful/stateless. I mean, after learning a bit more about native Flutter -- they go steful when they need to maintain the custom state f/mx handles at the CLJ level. Why does f/mx ever have to go there? 🤔

👍🏻 1
🔥 1
Benjamin C 2023-06-05T17:50:47.513639Z

> Are you able to toggle back and forth OK. What if you hit the first button twice, then hit the second? Hmm, yes this works without incident on my end. Granted I've patched state-set awhile ago because my bluetooth callbacks were trying to set state while things were still building. Not sure if that why or not, but just in case it's relevant. :

(defn state-set
  ([^State state]
   (state-set state nil))
  ([^State state me]
   (if (.-mounted state)
     (do (dpx :setting-state state (minfo me))
         (try (.setState state (fn [] (do)))
              (catch Exception e
                (Future.delayed Duration.zero
                                (fn [] (if (.-mounted state)) (.setState state (fn [] (do))))))
              #_ (finally (Future.delayed Duration.zero
                                (fn [] (if (.-mounted state)) (.setState state (fn [] (do))))))))
     #_(dp :NOT_SETTING_STATE_NOT_MOUNTED state (cty/minfo me)))))

kennytilton 2023-06-05T18:12:10.035059Z

Ah, I had jazzed things up a little:

(button (str "but does it?" (* 10 (mget (fasc :scaffo) :step)))
  (fn [] (mx/dp :button-2)))
I better see what's going on. 🕵️‍♂️

kennytilton 2023-06-05T21:21:01.933119Z

Not able to recreate. Meanwhile, I broke the x03-physics-sim example which expects the GD to have state. Hopefully just need to work in that "nearest state" utility:

(cF (when-let [st (fx/my-state)]
      (m/AnimationController .vsync st)))

👍🏻 1
kennytilton 2023-06-05T23:28:08.662759Z

So I changed the physics sim to search up to the nearest state, after making GD stateless, and got an error saying it was not a TickerProvider. WTF? A code search and I discover that, in desperation a year ago, I had splatted this line on exactly one factory variant, k1-child-stateful:

^:mixin m/SingleTickerProviderStateMixin ;; todo make optional
Love the comment. When I made GD k1-child-stateless, it lost the TickerProvider. The next state up was not a k1-child-stateful. Boom. I love this game!

😅 1
Benjamin C 2023-06-05T05:17:14.745989Z

Hmm, works fine without the fx/guesture-detector .