Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to check which one is the current route? #41

Closed
jlubeck opened this issue Apr 15, 2020 · 5 comments
Closed

Is there a way to check which one is the current route? #41

jlubeck opened this issue Apr 15, 2020 · 5 comments

Comments

@jlubeck
Copy link

jlubeck commented Apr 15, 2020

I have a navigation bar when I call Get.toNamed(routeName) whenever I tap on a button.

But I'd like to prevent that call when the currentRoute is the same as routeName.

Couldn't find a way to get the current route name except from within the middleware. Would be nice to get an accesor to the current route from Get directly, like Get.currentRoute or something

@jonataslaw
Copy link
Owner

jonataslaw commented Apr 15, 2020

class MiddleWare {
  static MiddleWare _instance;

  factory MiddleWare() {
    if (_instance == null) _instance = MiddleWare._();
    return _instance;
  }

  MiddleWare._();

  static Routing _routing;

  static Routing get routing => _routing;

  static observer(Routing rt) {
    _routing = rt;
  }
}

class Foo {
  yourMethod() {
  if(MiddleWare.routing.current == routeName){
  //Made anything
 }
 }
}

@jlubeck
Copy link
Author

jlubeck commented Apr 15, 2020

Awesome, thanks

@jlubeck jlubeck closed this as completed Apr 15, 2020
@esDotDev
Copy link

esDotDev commented Jun 26, 2020

Couple things:

  1. Can't we just get Get.CurrentRoute? Would be much nicer. The currently selected page is an important part of global state, should be readily accessible?
  2. Why do we have to do this (Create a Middleware class)... seems like a bizarre solution (just curious)

@jonataslaw
Copy link
Owner

Couple things:

  1. Can't we just get Get.CurrentRoute? Would be much nicer. The currently selected page is an important part of global state, should be readily accessible?
  2. Why do we have to do this (Create a Middleware class)... seems like a bizarre solution (just curious)

Currently Get.currentRoute does the job.
This issue is very old, it is version 1.0 of Get, at that time there were not even 1/3 of the resources that Get has today.

@esDotDev
Copy link

Ah, my bad. I assumed the list on pub.dev README was exhaustive.

Thanks for the framework, it's really impressive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants