Getx Routing

// Going to a page
Get.toNamed(AppLinks.DASHBOARD);
// Move back one page only
Get.offNamed(AppLinks.LOGIN);
// Going back all route/pages until LOGIN page you can even pass a predicate/ condition to pop until that condition passes
Get.offAllNamed(AppLinks.LOGIN);
// Pop the current route and to the defined route.
Get.offAllAndToNamed(AppLinks.ORDERS);

Passing Data between Routes.


//How we will pas data between routes.
// We can pass the data through bindings or better yet through our navigation functions
Get.to(AppLinks.DASHBOARD, arguments: { "username": "John Doe" });
// Later in the dashboard controller accessing the arguments
final args = Get.arguments;
// Since the arguments are passed in as a map you can access the username using Map access functionalities that dart provides
final username = args["username"];
//How we will pas data between routes.
// We can pass the data through bindings or better yet through our navigation functions
Get.to(AppLinks.DASHBOARD, arguments: { "username": "John Doe" });
// Later in the dashboard controller accessing the arguments



Bindings

You can add dependency injection required for you page using Get bindings. You create the binding by extending the Bindings class and inject all dependencies there.


class FavoritesBinding extends Bindings {
@override
void dependencies() {
// Lazily inject the dependency and only use the dependency when needed.
Get.lazyPut(() => FavoritesController());
}
}
/*
***Other Code**
*/
GetPage(
page: () => Favorites(),
binding: FavoritesBinding(),
middleware: [
AuthMiddleware(),
]
),
/**
Other code
*/

 

final args = Get.arguments;


Page Transitions.

Getx helps create nice routing animations by passing a simple transition to Get navigate function.


// Can be called within controllers
void toDashboard() {
Get.to(
AppLinks.DASHBOARD,
// Transition as a property. Different transitions can be applied. Such as
// fade,
// fadeIn,
// rightToLeft,
// leftToRight,
// upToDown,
// downToUp,
// rightToLeftWithFade,
// leftToRightWithFade,
// zoom,
transition: Transition.fadeIn
);
}

 

// Since the arguments are passed in as a map you can access the username using Map access functionalities that dart provides
final username = args["username"];
Rakibul hasan

I am Rakibul hasan,Front and Back-End Developer.I am also good at database like mysql,Firebase,mssql. I'm a Workaholic Person and I love my job as a mobile application developer i never get tired for it. Its been always fasinating to me working for new creation. I am very passionate about my work.I do my job passionately and dedicatedly.I try to do my project with clean code and gather efficiency. The greatest quality of mine is patience.I can code all day long. I never feel bored during coding and i can't take rest until my code is completed.I can adapt anything very quickly. I am also very sincere,responsible,hard working and confident regarding my works.Each and Every Project is important to me and I like to take Challenge.

Post a Comment

Previous Post Next Post