🚂Routing

Contextless navigation service

Are you frustrated about using BuildContext everytime when you navigate? Here comes the solution.

Pulse-X's navigation service relies on BuildContext but you won't have to use context everytime when you navigates to a screen or pops back to the original screen.

🚧 Pulse-X's navigator is still under implementation stage and only three functions have been implemented.

  • push

  • pushNamed

  • pop

But, first you'll have to do a few things in order to get contextless navigation.

Step 1:

Register Pulse-X's navigator key in your MaterialApp like this.

// ...your code...
MaterialApp(
    // other stuff
    navigatorKey: PulseXNavigator.navigatorKey,// register pulse's navigator key
);
// ...your code...

Step 2:

Register Pulse-X's navigation service in your dependency injection section like this.

PulseXInjector injector = PulseXInjector.instance;
injector.registerLazySingleton(() => PulseXNavigator());

Final Step:

Now, you can use Pulse-X's navigation service easily.

final _navigator = injector.find<PulseXNavigator>();

You can await return values from another screen.

final data = await _navigator.push(AnotherView());
              if(data != null){
                // do something
              }

For push method,

_navigator.push(AnotherView();

For pushNamed method,

🚧 still coding and testing, I'll let you know when it's ready

For pop method,

 _navigator.pop();

You can return arguments from pop method like this.

 _navigator.pop<String>("return value");

Last updated