Hey guys. I'd like to push the view without a Navigation View. I dont want the next view to have that possibility to go back.
I've build some viewModel I do wonder how can I use it throughout this operation.
Have an upper-most (or outer-most) view that checks some environment state and loads the appropriate view. I'll post some succinct-as-possible code here.
First, create some object to be held as an @EnvironmentObject that goes into the environment in @main, and show your main view, which is basically just a switch block for what to show in its confines. I don't like to junk up the @main file.
Main view is where all the which-view-to-show dispatching happens.
Then whenver you want to switch views without getting mucked up in stack based navigation, just grab your opDat reference and change the current view.
That triggers a redraw in MainView, reads the switch again, selects the appropriate view, and whammo, blammo, bob is still your uncle.
Doing this, you're still free to use NavigationView in any of the "top level" views like Settings or Home, etc., and still throw that whole stack away when it's time to navigate to another "top level" view. I use this model in pretty much every app.
implemented in the body of the SubView like this:
@chornbe answer is quite interesting. It is a sort of:
"How to navigate between Views without NavigationView"
My only concern is that you'll loose the structure and funcionality provided by NavigationView, and you MUST be very organized otherwise you will loose yourself (particulary in large projects)
I am curious about: viewModel.resetErrors() and would appreciate if @chornbe could elaborate. What kind of errors are expected to occur and why do you need to reset? Thx
Oh, that resetErrors function is just to clear any indicators I gave the user about missing or incorrect data. Sorry, it's outside the scope of this discussion and I probably should have chopped it out.
I use this navigation method in conjunction with the NavigationView model where it makes sense.
I look at most apps using only navigationView and I generally think that if you visualize them as walking paths, it rarely makes sense for everything to be just on one long winding path, and perhaps you see in front of you several doorways. One for Settings, one for data entry, one for journal viewing, etc (as abstract examples). Then each of those doorways might have a path (navigation stack) behind it, and you can just clear out and jump to another path, giving memory and resources to be cleaned up while you're off doing other things, and without 93 taps in the top left corner to always get back to home base before going off on another path.
In short, I find navigationview to be quirky and annoying, and requiring too much boilerplate (a la hiding the bar when it's not in the best interest of user experience) for simple things. I'd rather build UP those features than always having to tear them down. I'd go opposite on a number of defaults in UX were Apple to get wise and finally bring me on staff. ;) (Don't get me started on how much cruft I'd change, strip out, or light on fire in Flutter) :D
As for being very orgaized, IMO, that's as fundamental and foundational to being a developer as you can get. In fact, I'd say that the skill of "good coding" is probably the last thing or the least impactful thing on the list of requisite skills. I find that being an outstanding diagnostician and logicists analyst are far more important, and have led me in a ~35 year very fruitful career in software development (and IT writ large). :)
SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.