jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.33k stars 1.62k forks source link

[Question] Support for web? #1

Closed SiyrisSoul closed 4 years ago

SiyrisSoul commented 4 years ago

This looks promising to me! Just wondering how this works with web navigation? The /#/ in all web URL's currently is frustrating to deal with. Also does this pair nicely with animated routes?

I'm going to check these things out shortly as well :)

jonataslaw commented 4 years ago

This looks promising to me! Just wondering how this works with web navigation? The /#/ in all web URL's currently is frustrating to deal with. Also does this pair nicely with animated routes?

I'm going to check these things out shortly as well :)

Hi, this works perfectly with web. Flutter web compiles in javascript, so the routes are all defined with /#/ It is not possible to change this by plugin at this time, but maybe you can add some code that prevents this as

history.pushState("", document.title, window.location.pathname
                                                       + window.location.search);

I created a PWA module and another to work with SocketIO, which I will soon release in this Git. But for now I can only assure you that it will work on WEB, Desktop, and even Fuchsia, and that I can't change the behavior of adding / # / per hour. But if that becomes possible, I will insert it into this library. I added support for navigation with no context today, which will make this plugin indispensable for architectures like BLoC.

And the goal is to make this lib so robust that it is impossible to use standard navigation.

SiyrisSoul commented 4 years ago

@jonataslaw Awesome, thank you. I have actually removed the /#/ using what you suggested previously, I just didn't like that a user couldn't then copy and paste the URL and share it or even refresh the page without it not loading the same again.

jonataslaw commented 4 years ago

@jonataslaw Awesome, thank you. I have actually removed the /#/ using what you suggested previously, I just didn't like that a user couldn't then copy and paste the URL and share it or even refresh the page without it not loading the same again.

Hey guy, I added Flutter_web routes support Add to your MaterialApp:

   onGenerateRoute: Router.generateRoute,
    initialRoute: "/",
    navigatorKey: Get.key,

Copy this class and paste on your project with your classes names:

class Router {
  static Route<dynamic> generateRoute(RouteSettings settings) {
    switch (settings.name) {
      case '/':
        return GetRoute(
          builder: (_) => SplashScreen(),
          settings: settings,
        );
      case '/Home':
        return GetRoute(settings: settings, builder: (_) => Home());
      case '/Chat':
        return GetRoute(settings: settings, builder: (_) => Chat());
      default:
        return GetRoute(
            settings: settings,
            builder: (_) => Scaffold(
                  body: Center(
                      child: Text('No route defined for ${settings.name}')),
                ));
    }
  }
}

use "Get.toNamed("/Home");" for example, to navigate to route, and this name will appear on your site url, and remain when refresh.

That is all. I feel like I can close this issue already. Anything feel free to open it again.

SiyrisSoul commented 4 years ago

@jonataslaw Oh wow! That's awesome thank you.