flutter fluro
fluro is a flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.
features
- simple route navigation
- function handlers (map to a function instead of a route)
- wildcard parameter matching
- querystring parameter parsing
- common transitions built-in
- simple custom transition creation
version compatability
see changelog for all breaking (and non-breaking) changes.
getting started
you should ensure that you add the router as a dependency in your flutter project.
dependencies:
fluro: "^1.3.5"
you can also reference the git repo directly if you want:
dependencies:
fluro:
git: git://github.com/theyakka/fluro.git
you should then run flutter packages upgrade
or update your packages in intellij.
example project
there is a pretty sweet example project in the example
folder. check it out. otherwise, keep reading to get up and running.
setting up
first, you should define a new router
object by initializing it as such:
final router = router();
it may be convenient for you to store the router globally/statically so that
you can access the router in other areas in your application.
after instantiating the router, you will need to define your routes and your route handlers:
var usershandler = handler(handlerfunc: (buildcontext context, map<string, dynamic> params) {
return usersscreen(params["id"][0]);
});
void defineroutes(router router) {
router.define("/users/:id", handler: usershandler);
}
in the above example, the router will intercept a route such as/users/1234
and route the application to the usersscreen
passing
the value 1234
as a parameter to that screen.
navigating
you can use the router
with the materialapp.ongenerateroute
parameter
via the router.generator
function. to do so, pass the function reference to
the ongenerate
parameter like: ongenerateroute: router.generator
.
you can then use navigator.push
and the flutter routing mechanism will match the routes
for you.
you can also manually push to a route yourself. to do so:
router.navigateto(context, "/users/1234", transition: transitiontype.fadein);
Comments are closed.