A dank way to navigate in flutter
yeet
A dank way to navigate in flutter
How to yeet?
-
Install latest version of yeet:
dependencies:
flutter:
sdk: flutter
yeet: ^0.4.7 -
Define your yeets:
final yeet = Yeet(
children: [
Yeet(
path: '/',
builder: () => HomeView(),
),
Yeet(
path: r'/user/:id(\d+)',
builder: (ctx) => UserView(int.parse(ctx.params['id']!)),
children: [
Yeet(
path: 'posts',
builder: (ctx) => PostsView(int.parse(ctx.params['id']!)),
)
],
),
Yeet(
path: ':(.*)',
builder: (_) => NotFoundView(),
),
],
); -
Turn your
MaterialApp
intoMaterialApp.router
and add the following arguments.return MaterialApp.router(
routeInformationParser: YeetInformationParser(),
routerDelegate: YeeterDelegate(yeet: yeet),
); -
Set new paths.
context.yeet('/your/new/path');
context.yeet('can/be/relative'); -
And pop.
context.yeet();
-
Enjoy!
-
Missing a feature? Have a suggestion? Found a bug? Open an issue. Thanks!
Migrating from 0.3.2 to 0.4.0
- Parameters of
builder
have changed from(params, queryParams)
to just a single(context)
:
Before:
Yeet(
path: '/user/:id'
builder: (params, queryParams) => UserPage(id: params[id]!, edit: queryParams['edit'] ?? false)
)
After:
Yeet(
path: '/user/:id'
builder: (context) => UserPage(id: context.params[id]!, edit: context.queryParams['edit'] ?? false)
)
Now the page doesn't have to use the path or query parameters right away, and can always access it using the BuildContext
withing the build
function.
Yeet.custom
has been removed. Instead you can use thetransition
parameter to configure the page transition. Transition isYeetTransition.adaptive()
by default, which means that in iOS and macOS it's usingYeetTransition.cupertino()
and in other platformsYeetTransition.material()
.
Before:
Yeet.custom(
path: '/',
transitionsBuilder: ...,
opaque: ...,
//...
)
After:
Yeet(
path: '/',
transiton: YeetTransition.custom(
transitionsBuilder: ...,
opaque: ...,
//...
),
)