Skip to content

Instantly share code, notes, and snippets.

@valerauko
Last active November 1, 2022 14:13
Show Gist options
  • Select an option

  • Save valerauko/0b881d25103412897a3964b8b2a7e223 to your computer and use it in GitHub Desktop.

Select an option

Save valerauko/0b881d25103412897a3964b8b2a7e223 to your computer and use it in GitHub Desktop.
The kind of syntax I'd love to see for ClojureDart + Flutter
(ns flutter.playground
(:require [flutter.core :as f :refer [dispatch subscribe]]
[flutter.material :as m]))
(f/reg-event-fx
::to-counter
(fn [_ _]
{::f/navigator.pop []
::f/navigator.push-named [::counter]}))
(defn dialog
[]
[::m/alert-dialog
{:title "Are you sure?"}
:actions [[::m/text-button
{:on-pressed #(dispatch [::f/back])}
["Cancel"]]
[::m/text-button
{:on-pressed #(dispatch [::to-counter])}
["OK"]]]
"This will take you to the counter page"])
(f/reg-event-fx
::show-dialog
(fn [_ _]
{::f/show-dialog dialog}))
(defn home
[]
[::m/scaffold
{::m/app-bar
[{:title ["Home"]}]
::m/floating-action-button
[{:on-pressed #(dispatch [::show-dialog])
:tooltip "Take me to the counter!"}
[::m/icon
::m/icons.text-fields]]}])
(f/reg-event-db
::increment
(fn [db]
(update-in db [::count] inc)))
(f/reg-sub
::count
::count)
(defn counter
[]
[::m/scaffold
{::m/app-bar
[{:title ["Count on"]}]
::m/floating-action-button
[{:on-pressed #(dispatch [::increment])
:tooltip "Increment!"}
[::m/icon
::m/icons.add]]}
[::m/center
[::m/column
{::m/main-axis-alignment :center}
["You have pushed the button this many times:"]
[::m/text
{:style (-> (m/theme) :text-theme :display-large)}
@(subscribe [::count])]]]])
(def routes
["/"
[""
{:name ::home
:widget home}]
["counter"
{:name ::counter
:widget counter}]])
(defn main
[]
(-> routes (f/router) (m/run-app)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment