Comments (9)
@VikSin I just added go_router
sample. If we have time we'll add a pure cljd one without an external lib https://github.com/Tensegritics/ClojureDart/tree/main/samples/go_router
from clojuredart.
hello @VikSin -
The go
method they are using in this example is a Dart method extension -> https://dart.dev/language/extension-methods, they are available in ClojureDart but our syntax is not like a method call (that's the goal, we still have work on this part).
You have few ways to call the go
method from a widget:
- using
GoRouter.of
(f/widget :get [go/GoRouter] ... onPressed (fn [] (.go go-router '/details')))
- using
GoRouterState.of
(f/widget :get [go/GoRouterState] ... onPressed (fn [] (.go go-router '/details')))
- using the extension method syntax
.onPressed (fn [] (-> ctx go/GoRouterHelper (.go "/details")))
from clojuredart.
I'm getting error here -
java.lang.RuntimeException: Invalid token: /details'
clojure.lang.LispReader$ReaderException: java.lang.RuntimeException: Invalid token: /details'
Also I'm not sure if other parts here is correct or not. I have used chatGPT to help with coverting.
(def home-screen
(f/widget
:get [go/GoRouterState]
(m/Scaffold
.appBar (m/AppBar
.title (m/Text "Home screen"))
.body
(m/Center
.child
(m/ElevatedButton
.onPressed (fn [] (.go go-router '/details'))
.child (m/Text "Go to the details screen"))))))
(def details-screen
(f/widget
:get [go/GoRouterState]
(m/Scaffold
.appBar (m/AppBar
.title (m/Text "Details screen"))
.body
(m/Center
.child
(m/ElevatedButton
.onPressed (fn [] (.go go-router '/'))
.child (m/Text "Go to the home screen"))))))
(def router
(g/GoRouter
.routes [
(g/GoRoute
.path '/'
.builder
(f/build [contexr _]
(home-screen))
)
(g/GoRoute
.path '/details'
.builder
(f/build [context _]
(details-screen)))
]))
(defn main []
(f/run
(m/MaterialApp
.theme theme
.home (fn [] (g/navigate "/"))
.router-config router)))
from clojuredart.
@VikSin Baptiste inadvertently copied some Dart string in the middle of some ClojureDart, all 'strings'
should be "strings"
from clojuredart.
And how to write this part-
Widget build(BuildContext context) {
return MaterialApp.router(
routerConfig: _router,
);
}
from clojuredart.
(f/widget
:context ctx
(m/MaterialApp.router .routerConfig your-router))
Instead of the whole class MyApp extends...
from clojuredart.
Not getting any error but getting complete blank screen.
And Question: Doesn't m/MaterialApp part will be inside f/run? And If I have to include other config like theme for inside MaterialApp How I will do that here?
This go_router example is little bit different that other sample examples so getting confuse a lot here.
I'm just started learning this things.
here full code-
(ns app.main
(:require ["package:flutter/material.dart" :as m]
["package:go_router/go_router.dart" :as g]
[cljd.flutter :as f]))
(def theme
(m/ThemeData
.colorSchemeSeed m/Colors.yellow
.useMaterial3 true
.textTheme (m/TextTheme
.displayLarge (m/TextStyle
.fontWeight m/FontWeight.w700
.fontSize 24
.color m/Colors.black))))
(def home-screen
(f/widget
:context ctx
(m/Scaffold
.appBar (m/AppBar
.title (m/Text "Home screen"))
.body
(m/Center
.child
(m/ElevatedButton
.onPressed (fn [] (-> ctx g/GoRouterHelper (.go "/details")))
.child (m/Text "Go to the details screen"))))))
(def details-screen
(f/widget
:context ctx
(m/Scaffold
.appBar (m/AppBar
.title (m/Text "Details screen"))
.body
(m/Center
.child
(m/ElevatedButton
.onPressed (fn [] (-> ctx g/GoRouterHelper (.go "/details")))
.child (m/Text "Go to the home screen"))))))
(def router
(g/GoRouter
.initialLocation "/"
.routes [
(g/GoRoute
.path "/"
.builder home-screen
)
(g/GoRoute
.path "/details"
.builder details-screen)
]))
(defn main []
(f/widget
:context ctx
(m/MaterialApp.router .routerConfig router)))
from clojuredart.
In main
, replace f/widget
by f/run
since it's the entry point. You can also remove the :context ctx
line since ctx
is not used.
from clojuredart.
I have tried f/run and without :context ctx also getting errors-
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following _Exception was thrown building Builder(dirty):
Exception: No extension of protocol IFn found for type home_screenReify4wk9ma$1.
The relevant error-causing widget was:
Builder
Builder:file:///home/vikash/.pub-cache/hosted/pub.dev/go_router-14.0.2/lib/src/builder.dart:256:9
from clojuredart.
Related Issues (20)
- LD -XLinker is invalid option compiling for native app HOT 8
- multiple bindings in :bg-watcher
- Support multiple bindings in `:bg-watcher`
- platform conditionals HOT 3
- doseq and for but for streams
- Add a "nano pass" to the compiler to perform statements lifting
- Stop generating dart functions HOT 1
- Make magicast open
- `:keep-alive` on `f/widget` HOT 1
- Can't `with-open` HOT 2
- Printing cyclic data structure causes stack overlow HOT 1
- `doseq` with `await` in body evaluates to a future HOT 1
- cljd type parameter inference on static methods could be better
- Error: Can't use an expression of type 'void Function()?' as a function because it's potentially null.
- static methods on interfaces backing protocols
- Type hinting a `Future` fn won't compile
- Resolution of types across conditional import/export
- Loose type inference on functions that are type hinted
- (docs) Minor typo in the cheatsheet HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clojuredart.