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

Web like routing in flutter without stack #131537

Closed
2 tasks done
Aamir2000 opened this issue Jul 29, 2023 · 5 comments
Closed
2 tasks done

Web like routing in flutter without stack #131537

Aamir2000 opened this issue Jul 29, 2023 · 5 comments
Labels
r: invalid Issue is closed as not valid

Comments

@Aamir2000
Copy link

Is there an existing issue for this?

Use case

Web like routing ( without stack )

Hi Flutter Devs, I wanna request a feature and this is like actually really serious and something that should've existed in flutter for a long long time but for some reason it doesn't. I want in my applications to be able to navigate between different routes without having that strange stack routing thing. I need to be like web browsers.

  • It should not keep the widget I navigated off from active while its not on screen.
  • It should allow me to come back to previous screen when I press the back button just like in browsers
  • Flutter widgets should get destroyed once a user navigates off to another screen.
  • It should automatically maintain a history of navigation without us having to manually do it in our applications
  • Make it so that every widget and all the state related to that widget gets destroyed once the widget is navigated away from.
  • It should reinitialize the widget once the user comes back to the screen.
  • Provides a way to pass data around in route params and other means between routed pages or widgets.

What's the point you ask?

Well in most if not all applications in my usecases require camera, tons of forms and other things...with flutter stack based routing thing I have to manually conditionally dispose off all the data and close the camera otherwise it keeps the camera active.

For example a qr scanner keeps running and keeps scanning the same QR code millions of times even when I'm not even seeting the camera in the background. If I have logic to move to different screen on QR then it opens up duplicates of same screen multiple times thanks to its poorly thoughtout routing system.

It's really a rant at this point. Just because of it's routing and bad syntax of callback hell I was keeping away from this framework but I'd consider you can atleast fix 1 major problem like routing in this thing.

Dart is such a cool language but not sure what benefit that callback hell syntax gives flutter over just simple language like dart. Browser vendors like dying to prevent callback hells with promises in javascript and here we are using it like no tomorrow. although I'd leave the thought of ever seeing flutter fixing and rewriting the whole framework again.

Proposal

Make flutter routing more like React native or Ionic

@iapicca
Copy link
Contributor

iapicca commented Jul 30, 2023

  • It should not keep the widget I navigated off from active while its not on screen.
  • It should allow me to come back to previous screen when I press the back button just like in browsers
  • Flutter widgets should get destroyed once a user navigates off to another screen.
    [...]
  • Make it so that every widget and all the state related to that widget gets destroyed once the widget is navigated away from.
    [...]
  • Provides a way to pass data around in route params and other means between routed pages or widgets.

go_router covers these points

  • It should automatically maintain a history of navigation without us having to manually do it in our applications

not sure of what you mean, but sounds like state restoration to me;
I'd rather have it as an option rather than something auto-enabled by default

  • It should reinitialize the widget once the user comes back to the screen.

it really depends from the type of navigation:

  • given a foo/bar structure ,when you are on bar and pop,foo shouldn't rebuild (by default)
  • given 2 separate routes, when you navigate or go back from one to another, the new one is rebuild and the old destroyed

this is the current implementation afaik

@Aamir2000
Copy link
Author

@iapicca go_router is no better than the flutter implementation of routing itself. Either it replaces or creates a stack both of which flutter already provides. What I really want is more browser like navigation. If you're aware of browser navigation it doesn't create stacks instead completely removes the current page and renders a new one while maintaing the history.

Btw I did try go_router FYI and it does no good for me it does nothing special that flutter doesn't already do.

@iapicca
Copy link
Contributor

iapicca commented Jul 30, 2023

What I really want is more browser like navigation.

Flutter is not web based, for some may be a minus, for other like me is a plus;
asking "I want flutter to be more 'web-based like'" seems a bit unrealistic imho.

Could be useful if you could point out
something that cannot be done with flutter's navigation options,
the your list doesn't seem to point at anything that isn't already available

@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Jul 31, 2023
@darshankawar
Copy link
Member

@Aamir2000
Apart from the good points made by @iapicca, you may also note that the way navigation works today is by keeping the navigation stack in memory, ie the stack is destroyed on page refresh, and the history is lost.

As pointed above already, you should take a look at navigator 2.0 to understand how Flutter handles the navigation and also state restoration which gives app developers the possibility to store state and recover it after a page refresh (or after the app is killed in the background on mobile ).

There's also an open issue you can track for navigator 2.0 and state restoration for web if that interests you: #65777

Another issue you may want to check is #108114 and see if it relates to your use case or not.
Moreover, check if this helps in your case or not.

Make flutter routing more like React native or Ionic

This is a very generic proposal which may not be feasible / practical to achieve and not complete to make this issue actionable.

If you are facing any specific challenges when it comes to navigation or using go_router package, I suggest you to file separate issues with proper code sample along with current limitation and expected behavior you are looking for, so that we can properly evaluate and address those issues as applicable.

With above given details, I am going ahead and closing this issue. If you disagree, write in comments or open new issue with specific cases and we'll address them.

@darshankawar darshankawar closed this as not planned Won't fix, can't repro, duplicate, stale Jul 31, 2023
@darshankawar darshankawar added r: invalid Issue is closed as not valid and removed in triage Presently being triaged by the triage team labels Jul 31, 2023
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
r: invalid Issue is closed as not valid
Projects
None yet
Development

No branches or pull requests

3 participants