Tensegritics / ClojureDart

Clojure dialect for Flutter and Dart
1.44k stars 91 forks source link

bug in TextField onChanged `Can't return a value from a void function.` #249

Closed rgkirch closed 1 year ago

rgkirch commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

Does your problem persist after clj -M:cljd clean && flutter clean? yes

To Reproduce

(defn seven-guis-temperature-converter
  ([] (seven-guis-temperature-converter (atom 0)))
  ([state]
   (let [c-to-f (fn [c] (+ 32 (* c (/ 9 5))))
         f-to-c (fn [f] (* (- f 32) (/ 5 9)))]
     (f/widget
      :let [temp-c (or @state 0)]
      :managed [c-tec (m/TextEditingController .text (str temp-c))
                f-tec (m/TextEditingController .text (str (c-to-f temp-c)))]

      (m/SizedBox
       .height 100
       .child
       (m/Row
        .mainAxisAlignment m/MainAxisAlignment.center
        .children
        [(f/widget
          (m/SizedBox .width 150)
          (m/TextField .controller c-tec
                       .onChanged (fn [x] (set! (.-text f-tec) (str (c-to-f (int.parse x)))))
                       .decoration (m/InputDecoration .border (m/OutlineInputBorder)
                                                      .labelText "Celsius")))
         (m/Text " = " .style (m/TextStyle .fontSize 32.0))
         (f/widget
          (m/SizedBox .width 150)
          (m/TextField .controller f-tec
                       .onChanged (fn [x] (set! (.-text c-tec) (str (f-to-c (int.parse x)))))
                       .decoration (m/InputDecoration .border (m/OutlineInputBorder)
                                                      .labelText "Fahrenheit")))]))))))
lib/cljd-out/main.dart:300:8: Error: Can't return a value from a void function.
return arg$1;
       ^
lib/cljd-out/main.dart:306:8: Error: Can't return a value from a void function.
return arg$2;

if I edit the dart

    fl$2[2] = f_material.SizedBox(
      width: 150.0,
      child: f_material.TextField(
        controller: f_tec$1,
        onChanged: (
          dc.dynamic x$2,
        ) {
          final dc.String arg$2 = (lcoc_core.str.$_invoke$1(
            f_to_c$1(
              (dc.int.parse(
                (x$2 as dc.String),
              )),
            ),
          ));
          c_tec$1.text = arg$2;
          return arg$2;
        },
        decoration: const f_material.InputDecoration(
          border: const f_material.OutlineInputBorder(),
          labelText: "Fahrenheit",
        ),
      ),
    );

and remove

          return arg$2;

then the error goes away and the program works

dupuchba commented 1 year ago

add nil after the (set!...) in your onChange. onChange must return a nil value if we look at the TextField doc

rgkirch commented 1 year ago

🤦‍♂️ Thanks!