Skip to content

Instantly share code, notes, and snippets.

@perpen
Created July 19, 2022 07:52
Show Gist options
  • Save perpen/40e26b445034e6389651abc108b3edee to your computer and use it in GitHub Desktop.
Save perpen/40e26b445034e6389651abc108b3edee to your computer and use it in GitHub Desktop.
(ns sample.navigation
"Port of https://docs.flutter.dev/cookbook/navigation/navigation-basics"
(:require
["package:flutter/material.dart" :as m]
[cljd.flutter.alpha :as f]))
(def second-route
(f/widget
:inherit [m/Navigator]
(m/Scaffold
.appBar (m/AppBar .title (m/Text "Second Route"))
.body
(f/nest
m/Center
(m/ElevatedButton .onPressed #(.pop navigator))
(m/Text "Go back!")))))
(defn goto [ctx nav]
(.push
nav
ctx
(#/(m/MaterialPageRoute Object) .builder (fn [_] second-route)))
nil)
(def first-route
(f/widget
:context ctx
:inherit [m/Navigator]
(m/Scaffold
.appBar (m/AppBar .title (m/Text "First Route"))
.body
(f/nest
m/Center
(m/ElevatedButton
.onPressed (fn [] (goto ctx navigator)))
(m/Text "Open route")))))
(defn main []
(m/runApp
(m/MaterialApp
.title "Navigation Basics"
.home first-route)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment