Created
July 19, 2022 07:52
-
-
Save perpen/40e26b445034e6389651abc108b3edee to your computer and use it in GitHub Desktop.
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
(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