-
-
Save marenovakovic/5daba2fb5ebb83a93f9ce6314ce7fb9f to your computer and use it in GitHub Desktop.
Counter Flutter app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module fsharp.Main | |
open Flutter.Foundation | |
open Flutter.Rendering | |
open Flutter.Widgets | |
open Flutter.Material | |
open Elmish | |
open Elmish.Flutter | |
type Model = { count: int } | |
type Msg = | |
| Increment | |
| Decrement | |
let init () = { count = 0 }, Cmd.none | |
let update msg model = | |
match msg with | |
| Increment -> { model with count = model.count + 1 }, Cmd.none | |
| Decrement -> { model with count = model.count - 1 }, Cmd.none | |
let buttons dispatch : Widget = | |
Row( | |
mainAxisAlignment = MainAxisAlignment.center, | |
children = | |
[| MaterialButton(child = Text("Increment"), onPressed = fun () -> Increment |> dispatch) | |
MaterialButton(child = Text("Decrement"), onPressed = fun () -> Decrement |> dispatch) | |
SizedBox(width = 8) |] | |
) | |
let view model dispatch context : Widget = | |
Scaffold( | |
appBar = AppBar(title = Text("Hello from F#!")), | |
body = | |
Center( | |
child = | |
Column( | |
mainAxisAlignment = MainAxisAlignment.center, | |
children = | |
[| Text("Count:") | |
Text(model.count |> string) | |
SizedBox(height = 8) | |
buttons dispatch |] | |
) | |
) | |
) | |
type MyApp(?key: Key) = | |
inherit StatelessWidget(?key = key) | |
override _.build(context) = | |
MaterialApp(title = "Hello from F#!", home = ElmishWidget.From(init, update, view)) | |
let main () = MyApp() |> runApp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment